How can I remove objects from array based on multiple conditions?

I have this array of objects that I want to filter based on these rules:

If more than one object has team and day are the same, remove the objects with the lowest Level
but if more than one object with same lowest Level then remove the one with the lowest strength
if there’s still more than one remove one with the lowest ability.

Thought about creating a new array after each condition, then, also tried to come up with a way of doing it with all the conditions, and I am so lost with it I don’t know where I’m up to.

I also tried creating an empty array and pushing the objects that meet the rules into it, but ended up having to meet all the rules anyway and was still just as complicated.

const players = [
  { Level: 1, team: 'green', strength: 2, ability: 2, day: 1 },
  { Level: 1, team: 'red', strength: 2, ability: 2, day: 2 },
  { Level: 1, team: 'red', strength: 2, ability: 2, day: 3 },
  { Level: 1, team: 'silver', strength: 2, ability: 2, day: 3 },
  { Level: 1, team: 'red', strength: 2, ability: 2, day: 4 },
  { Level: 1, team: 'silver', strength: 2, ability: 2, day: 4 },
  { Level: 1, team: 'red', strength: 2, ability: 2, day: 5 },
  { Level: 1, team: 'silver', strength: 2, ability: 2, day: 5 },
  { Level: 2, team: 'red', strength: 2, ability: 4, day: 4 },
  { Level: 2, team: 'red', strength: 2, ability: 4, day: 5 },
  { Level: 1, team: 'silver', strength: 2, ability: 2, day: 1 },
  { Level: 1, team: 'silver', strength: 2, ability: 2, day: 2 },
  { Level: 2, team: 'red', strength: 2, ability: 3, day: 1 },
  { Level: 2, team: 'silver', strength: 2, ability: 3, day: 1 },
  { Level: 2, team: 'red', strength: 2, ability: 3, day: 2 },
  { Level: 2, team: 'silver', strength: 2, ability: 3, day: 2 },
  { Level: 2, team: 'red', strength: 2, ability: 4, day: 1 },
  { Level: 3, team: 'red', strength: 3, ability: 4, day: 1 },
  { Level: 3, team: 'red', strength: 3, ability: 4, day: 2 },
  { Level: 3, team: 'red', strength: 3, ability: 4, day: 3 }
];

31 thoughts on “How can I remove objects from array based on multiple conditions?”

  1. 876328 914059Youre so cool! I dont suppose Ive read anything like this before. So good to search out any individual with some original thoughts on this subject. realy thank you for starting this up. this site is 1 thing thats wanted on the internet, somebody with a bit of originality. useful job for bringing something new to the internet! 879445

    Reply
  2. 763299 867019Possible demand all types of led tourdates with some other fancy car applications. Numerous also give historic packs and other requires to order take into your lending center, and for a holiday in upstate New York. ??? 389911

    Reply