
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Start by declaring a new array which will eventually be returned.
In Javascript, there is the concept of "truthiness" and "falsiness". Values such as 0, undefined, null, and false are falsy. Most values are truthy: 1, {}, [], true, etc. In Javascript, the contents of if-statements don't need to be booleans. You can say "if ([1,2,3]) {}", and it's equivalent to saying 'if (true) {}".
Loop over each element in the array. If fn(arr[i]) is truthy, push it to the array.