Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

predicate function javascript

const numbers = [1,2,3,4,5,6];
// The following function is a Predicate one
// It takes a value and returns true/false
function isEven(number){
  return number % 2 === 0;
}
// Create an array containing the even nbs only
const evenNumbers = numbers.filter(isEven);

console.log(evenNumbers); // [ 2, 4, 6 ]
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #predicate #function #javascript
ADD COMMENT
Topic
Name
7+2 =