Write a JavaScript program to create an array of elements, ungrouping the elements in an array produced by zip and applying the provided function
- برمجة
- برمجة جافاسكربت java script
- 2021-06-03
- ahmadghneem
الأجوبة
const unzipWith = (arr, fn) =>
arr
.reduce(
(acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc),
Array.from({
length: Math.max(...arr.map(x => x.length))
}).map(x => [])
)
.map(val => fn(...val));
console.log(unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)));
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال