georgiev955

mergeArrays

May 31st, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mergeArray(firstArray, secondArray) {
  2.     let newArray = new Array(firstArray.length).fill(0);
  3.     for (let index = 0; index < firstArray.length; index++) {
  4.         if (index % 2 === 0) {
  5.             newArray[index] = Number(firstArray[index]) + Number(secondArray[index]);
  6.         } else {
  7.             newArray[index] = firstArray[index] + secondArray[index];
  8.         }
  9.     }
  10.     console.log(newArray.join(' - '));
  11. }
Advertisement
Add Comment
Please, Sign In to add comment