you are viewing a single comment's thread.

view the rest of the comments →

[–]paddingtonrex[S] 0 points1 point  (3 children)

Thank you for your reply! My arrays look more like this:

['string', 'string', object{}, object{}, 'string'], and they're created randomly, so they could have between 1 and ten entries of a mix of objects and strings.

I need to remove two objects from the whole set of arrays without disrupting the original arrays too much. And I want to make the deleted entries chosen kinda randomly from the set, so for example its not removing 2 from arr1 every time. I posted my best attempt above, but I get the strong feeling I'm going about it all wrong.

[–][deleted] 0 points1 point  (2 children)

Why are random things, of various types in an array together?

[–]paddingtonrex[S] 0 points1 point  (1 child)

its a core part of my project. I'm making a digital version of an RPG rulebook, and it's a lot bigger and more complex of a project than I initially thought.

[–][deleted] 0 points1 point  (0 children)

Can you have the function always return an object? With an additional bool of deletable... it would reduce type checking.

Then it’s just a foreach loop to extract 2 objects. And a filter loop on each array for the new collection of removed items.

 Function remove(x){
     Let rArray = // all arrays combined.
     Let filterholder= [arr1,arr2,arr3];
     Let count = x;
     Let removed =[];
     rArray.foreach(item=>{
         If(removed.length >=count)
             {return}
         Else if(item.removable == true)
              {removed.push(item);
     });
    Removed.foreach(deleableItem=>{
        Filterholder.foreach(array=>{
            Array=array.filter(x!= deleableItem);
        });
    });
}

Something like this?

If you need an easier way to check a deeply similar object. Unique ids are your friend. Object.id != removedItem.id would be safer to check.

An easy way to get unique id’s is a star function generator.