I was asked to filter out NaN, null, 0, false in an array.
Luckily I have answered the question.
function bouncer(arr) {
function filterer(arr) {
return arr > 0|| isNaN(arr) === true;
}
arr = arr.filter(filterer);
return arr;
}
//example input
bouncer([0, 1, 2, 3, 'ate', '', false]); //output [1, 2, 3, 'ate']
but the thing is I really don't know how I came up with the answer or rather I don't know how it works. Specially on arr > 0 how did the filter know that arr is alread on arr[1], arr[2], etc.. without using a loop to iterate in all array.
or can simply just explain on how to code works. [I've tried to explain it clearly ---]