Answers for "add even numbers recursion js"

0

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));
Posted by: Guest on March-21-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language