Advertisement
dabidabidesh

mergeArrays

Jun 5th, 2020
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //03.Merge Arrays
  2. function mergeArrays(arr1, arr2) {
  3.   'use strict'
  4.  
  5.   let thirdArr = []
  6.   let output = ''
  7.   for (let i = 0; i < arr1.length; i++) {
  8.  
  9.     if (i % 2 === 0)
  10.       thirdArr[i] = +arr1[i] + +arr2[i]
  11.     else
  12.       thirdArr[i] = arr1[i] + arr2[i]
  13.  
  14.     if (i === arr1.length - 1)
  15.       output += `${thirdArr[i]}`
  16.     else
  17.       output += `${thirdArr[i]} - `
  18.   }
  19.   console.log(output)
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement