Advertisement
Spocoman

04. Odd And Even Sum

Jan 28th, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (number) {
  2.     let num = [...number.toString()].map(Number);
  3.  
  4.     function sumOddAndEvenNum() {
  5.  
  6.         let oddSum = 0;
  7.         let evenSum = 0;
  8.        
  9.         for (let i = 0; i < num.length; i++){
  10.             if ( num[i] % 2 === 1){
  11.                 oddSum += num[i];
  12.             } else {
  13.                 evenSum += num[i];
  14.             }
  15.         }
  16.  
  17.         return `Odd sum = ${oddSum}, Even sum = ${evenSum}`;
  18.     }
  19.  
  20.     console.log(sumOddAndEvenNum());
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement