Answers for "filter function using recursion"

0

filter function using recursion

function exclude(arr, fn, output) {
  output || (output = []);
  
  if(!arr.length) { 
    return output;
  }
  
  if (fn(arr[0])) {
    output.push(arr[0]);
  }

  return exclude(arr.slice(1), fn, output);
}

console.log(exclude([1,2,3,4,5,6,7,8,9], function(i) { return i % 2; }));
 Run code snippet
Posted by: Guest on October-20-2021

Code answers related to "filter function using recursion"

Browse Popular Code Answers by Language