Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: remove object if key is duplicate javascript 
Javascript :: drag drop in blazor 
Javascript :: TypeError: path must be absolute or specify root to res.sendFile 
Javascript :: usestate callback 
Javascript :: redux action 
Javascript :: random color generator 
Javascript :: groubbykey js 
Javascript :: first node prog using express 
Javascript :: sort object with certain value at start of array js 
Javascript :: spray scala JSON formatter override def read examples 
Javascript :: round down js 
Javascript :: jquery select input value empty and hasclass 
Javascript :: how to add image url in tailwindconfig .js 
Javascript :: datepicker toltip 
Javascript :: how to change created_at format with javascript rails 
Javascript :: ajaxsetup beforesend 
Javascript :: javascript return value from async function 
Javascript :: window onfocus 
Javascript :: push element in array javascript 
Javascript :: how to transform object in string with scaped 
Javascript :: formating decimal hours as hours and minute javascript 
Javascript :: angular material dialog close pass data 
Javascript :: how to connect socket in react js 
Javascript :: Highest and Lowest 
Javascript :: calculate age given the birth date in the format yyyymmdd 
Javascript :: javascript function to sleep 
Javascript :: download pdf from drive js 
Javascript :: calculate sum in empty array javascript 
Javascript :: js get files 
Javascript :: javascript add to undefined 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =