Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add even numbers recursion js

const recursiveEvenSum = (num, sum = 0) => {
   num = num % 2 === 0 ? num : num - 1;
   if(num){
      return recursiveEvenSum(num - 2, sum+num);
   }
   return sum;
};
console.log(recursiveEvenSum(12));
console.log(recursiveEvenSum(122));
console.log(recursiveEvenSum(23));
console.log(recursiveEvenSum(10));
console.log(recursiveEvenSum(19));
Comment

PREVIOUS NEXT
Code Example
Javascript :: vue displaying a this.length 
Javascript :: how to get circle around text in react natvie 
Javascript :: js get each pair of values from an array of objects 
Javascript :: html anchor tag javascript confirm 
Javascript :: The element.parentNode Property 
Javascript :: check if an array contains a number in javascript 
Javascript :: Material-ui Accessible icon 
Javascript :: postgres boolean column 
Javascript :: select parent of elemt 
Javascript :: javascript find the longest word in a string 
Javascript :: electron load index.html 
Javascript :: make an object javascript 
Javascript :: Reusable Alpine.js components 
Javascript :: axios all methods 
Javascript :: Appending the option element using jquery each function 
Javascript :: get filenem js 
Javascript :: moment is today 
Javascript :: javascript get second last element of array 
Javascript :: get height webview from url video react native 
Javascript :: javascript typeof 
Javascript :: remove duplicates in array 
Javascript :: js stringify 
Javascript :: javascript + sync for loop 
Javascript :: how to copyy a string variable to clipboard in js 
Javascript :: javascript filter array match includes exact 
Javascript :: arrays inside array of objects 
Javascript :: get id in url params 
Javascript :: discord.js make channel private 
Javascript :: null data type in javascript 
Javascript :: Convert array to string while preserving brackets 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =