I bump into this challange: https://www.freecodecamp.com/challenges/falsy-bouncer
By reading desc of task, u need to remove “falsy” boolean values. So i tried something like this:
EDIT: At the first moment, i link to challange with code, but think link is to large for showing whole code so here is:
function isFalsy(value){
return (value !== false) && value !== null && value !== "" && value !== undefined && value !== 0 && typeof(value) !== NaN;
}
var haveString = true;
function bouncer(arr) {
// Don't show a false ID to this bouncer
console.log(arr);
arr = arr.filter(isFalsy);
console.log(arr);
return arr.length === 0 ? []:arr;
}
bouncer([7, "ate", "", false, 9]);
And can’t figure out how on one side can have function that check if value is NotANumber and remove if so, and on other have String
Something like:
bouncer([7, “ate”, “”, false, 9]) should return [7, “ate”, 9]
bouncer([1, null, NaN, 2, undefined]) should return [1, 2]
But with this code works perfectly:
function isFalsy(value){
return value;
}
function bouncer(arr) {
// Don't show a false ID to this bouncer
console.log(arr);
arr = arr.filter(isFalsy);
console.log(arr);
return arr;
}
bouncer([7, "ate", "", false, 9]);