Functional Programming: Use the every Method to Check that Every Element in an Array Meets a Criteria

Functional Programming: Use the every Method to Check that Every Element in an Array Meets a Criteria
0

#1

Tell us what’s happening:

Your code so far


function checkPositive(arr) {
  // Add your code below this line
   return arr.every(item => {
     return (item > -1) ? true : false;
   });
  // Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria


#2

Your code passes the tests, though I would say 0 is not a positive number.

Also, item > -1 is an expression which will evaluate to true or false, so you do not need to use the ternary operator. Just return the expression.


#3

Here is the simplified code

[spoiler]

function checkPositive(arr) {
  // Add your code below this line
  return arr.every(pos => pos > -1);
  
  // Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);

[\spoiler]