const originList = [
[1, 2],
[3, 4, 5],
[6, 7, 8, 9],
];
const reduceZipResult = originList.reduce((acc, cur, idx) => {
for (let i = 0; i < cur.length; i++) {
let el = acc[i];
if (el === undefined) {
el = [];
for (let j = 0; j < i; j++) {
el[j] = undefined;
}
//el = Array(cur.length).fill(undefined);
}
el[idx] = cur[i];
acc[i] = el;
}
return acc;
}, []);
console.log(reduceZipResult);
'개발 > JavaScript' 카테고리의 다른 글
[Typescript] type 및 try-catch 시 return 처리 (0) | 2024.09.13 |
---|---|
자바스크립트의 프로토타입 - 자바스크립트 핵심 가이드 (0) | 2024.02.22 |
함수형 프로그래밍 - Reduce를 활용하여 Map, Filter 구현하기 (0) | 2023.10.10 |
lodash :: _.zip()과 _.unzip() 구현하기 (1) | 2023.10.08 |
lodash :: _.uniq(array) 구현하기 (0) | 2023.10.08 |