I dont really understand this solution and hoping for some clarification.
The task: Remove all falsy values from an array. Return a new array; do not mutate the original array.
I dont understand how this solution identifies what is a falsy value. Wouldn’t this solution just push every array element, regardless if it is falsy or not?
function bouncer(arr) {
let newArr = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i]) newArr.push(arr[i]);
}
return newArr;
}
console.log(bouncer([7, "ate", "", false, 9]));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0
It is best to look at the posted solutions after you write your own solution. The more you look up solutions, the less you will be able to write your own solutions.
I am being direct. I’m asking questions and replying based upon the information you give.
Again, ignore the written solution. Copying answers cripples your ability to create your own code. There are not answers to copy for the certification projects (unless you cheat, which will result in your certification being revoked).
Do you know how to convert a value to a boolean? There are many ways to do this. The written solution uses one (again, ignore it for now), but there are many more. Understanding how to treat a value as a boolean is the entire point of this challenge.
If you can write at least one way of converting a value into a boolean, then you can write a solution to this challenge.