I have a program that adds or removes cars to an array called pile so that the cars can later be selected based on filters and criteria. The code works as it is but I am trying to increase it's efficiency for later changes. Below is code to show what my question is:
if ( var1 == true ) {
pile.push(car1);
} else if ( var1 == false ) {
pile = pile.filter( removeCar );
}
function removeCar(elem) {
return String(elem[0][0]) !== 'Jeep';
}
What I want to do is for removeCar() to have two parameters so it is removeCar(elem, make) such that if make = 'Jeep' the code would function the same way. Unfortunately, as you can see removeCar is called by filter with no parameters and elem is automatically assigned to the current element.
How can I add parameters to the .filter( removeCar)?
trueto the variables and do not make a check with it.If(var1 = true)will always be true because thats assignment and you will never get to the else. Also in the else you don't need to test if its false again because if it's not true it will be false assuming that its a boolean ofcourse. Now you can pass in values in to a function by sopile = pile.filter( elem => removeCar(elem) );===but this would work