thecodingaviator on master
remove A (#31157) (compare)
@ahmadabdolsaheb - without knowing all that you're doing, how about not calling the
.filter when you don't want to actually filter, or if you make a "control" variable like this:
let doAll = true; cards = cards.filter(card=> card.type == "awards" || doAll );
So that you can set
doAll to the value you want (based on some condition) and then it would always pass the test? That's at least one take at it... You have to catch the return from the
.filter, so I just threw that in there...
array = [1,2,3,5]; console.log(array.filter(num => num == true));only returns one
cards.filter(card=> card.type == "awards")
cards.filter(card=> card.type === "awards")
cards.filter(card => card.type)would also keep all cards provided that types are non-empty strings.
cards = cards.filter(card=> card.type == "awards" || doAll );- the variable
doAllwould be set to
false(or something that evaluated to true or false) and if it did not match the first conditional test, then if
true, it would add the card to the output array. It is the
||"or" condition that makes it work. It is a common way to affect conditional tests. So it will work, but it might not always be the best way to do things, for example, if you have a 1000 element array that you don't need to filter, then maybe it is not too efficient to do this (just thinking of performance).