silvana1303

even odd substraction

Apr 7th, 2021
304
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function  solve(arr){
  2.  
  3.     let arrayEven = [];
  4.     let arrayOdd = [];
  5.  
  6.     let evenSum = 0;
  7.     let oddSum = 0;
  8.  
  9.     for (let i = 0; i < arr.length; i++) {
  10.         let number = arr[i];
  11.  
  12.         if (number % 2 == 0){
  13.             arrayEven.push(number);
  14.         }
  15.         else{
  16.             arrayOdd.push(number);
  17.         }
  18.  
  19.     }
  20.  
  21.     if (arrayEven.length > 0){
  22.         evenSum = arrayEven.reduce((a, b) => a + b);
  23.     }
  24.  
  25.     if (arrayOdd.length > 0){
  26.         oddSum = arrayOdd.reduce((a, b) => a + b);
  27.     }
  28.    
  29.     let sum = evenSum - oddSum;
  30.  
  31.     console.log(sum);
  32.  
  33. }
  34.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×