Falsy Bouncer :my solution using spread operators

My solution!

function bouncer(arr) {

  let newArr=[...arr].filter(Boolean);

  let updatedArr=[...newArr];

  return updatedArr;

 }

bouncer([7, "ate", "", false, 9]);

Welcome to the forum ^^
While we are always happy to see people succeed and come up with clever tricks, please don’t share working solutions on the forum. Or at the very least use the spoiler-tags (located under the cog-symbol above the text-field).

The idea of the forum is to help people find mistakes in their code, not to directly tell them how to do it :wink:

1 Like

It is great that you solved the challenge, but
we are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.

In future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code. I’ve added that to your post in this case.


Note that, with respect to your solution, you copy the array three times for no reason. You can replace all of the code with

return arr.filter(Boolean)

And that will have exactly the same effect, but only create one new array.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.