Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Understanding higher order JavaScript functions

function evenNumberFilter(number) {
  return number %2 == 0
}

function oddNumberFilter(number) {
  return !evenNumberFilter(number)
}

function filter(predicate) {
  const result = []
  for(number=0; number<10; number++) {
    if (predicate(number)) {
      result.push(number)
    }
  }
  return result
}

filter(evenNumberFilter);  //[0,2,4,6,8]
filter(oddNumberFilter);   //[1,3,5,7,9]
Source by www.google.com #
 
PREVIOUS NEXT
Tagged: #Understanding #higher #order #JavaScript #functions
ADD COMMENT
Topic
Name
9+9 =