I just solved the Falsy Bouncer challenge in the Basic Algorithm Scripting section, but I had another idea for a solution that doesn’t seem to work, and I’m wondering why.
Here’s the solution that worked:
[code]function bouncer(arr) {
function notFalsy(i) {
if(i !== false){
return i;
}
}
return arr.filter(notFalsy);
}
bouncer(variousArrays);[/code]
and the other solution, which I thought was simpler, but seems not to work:
[code]function bouncer(arr) {
function notFalsy(i) {
return i !== false;
}
return arr.filter(notFalsy);
}
bouncer(variousArrays);[/code]
This second solution was more in the vein of the leading example provided by MDN on Array.prototype.filter(), but it seems like maybe it doesn’t work the same way with boolean values. It seems to me like the two above solutions should be functionally the same and only syntactically different, but obviously that’s not the case.
Any help appreciated, thanks!