:
, , ():
let arr1 = ['golf', 'hockey', 'tennis'];
let arr2 = ['player1', 'player2', 'player3']
Array.prototype.zip = function (arr) {
return this.map(function (e, i) {
return [ e, arr[i]]
}).reduce((a,b)=>a.concat(b));
};
const arr3 = arr1.zip(arr2)
console.log(arr3)
This approach preserves what you have and does not contain many complexities, such as additional method calls, temp arrays, etc .; what is the beauty of a functional approach: you are one chain link from what you need. I would also convert it to the stand method, instead of modifying the prototype, but away from the point ...
source
share