desito07

Add and Subtract

Jun 6th, 2020
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function addOrSubtract(arr) {
  2.   let arrNew = [];
  3.   let arrNewSum = 0;
  4.   let arrSum = 0;
  5.  
  6.   for (let i = 0; i < arr.length; i++) {
  7.     arrSum += arr[i];
  8.     let result = arr[i];
  9.     if (result % 2 === 0) {
  10.       result += i;
  11.       arrNewSum += result;
  12.     } else {
  13.       result -= i;
  14.       arrNewSum += result;
  15.     }
  16.  
  17.     arrNew.push(result);
  18.   }
  19.   console.log(arrNew);
  20.   console.log(arrSum);
  21.   console.log(arrNewSum);
  22. }
  23. addOrSubtract([5, 15, 23, 56, 35]);
Advertisement
Add Comment
Please, Sign In to add comment