Advertisement
Pijomir

Odd And Even Sum

Aug 16th, 2022
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculateEvenAndOddSums(num) {
  2.     let arrOfNumbers = num.toString().split('').map(Number);
  3.     let oddSum = arrOfNumbers.filter(a => a % 2 === 1).reduce((a, b) => a + b);
  4.     let evenSum = arrOfNumbers.filter(a => a % 2 === 0).reduce((a, b) => a + b);
  5.  
  6.    console.log(`Odd sum = ${oddSum}, Even sum = ${evenSum}`);
  7. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement