function arraysLaminated(...args) {
let result = []
const argsLen = args.length
const argChildLen = args.map(v => v.length)
const argChildLenSort = [...argChildLen].sort((a,b)=>a>b?1:-1)
const firstLen = argChildLenSort[argsLen - 1]
const secondLen = argChildLenSort[argsLen - 2]
// console.log(argChildLenSort)
let childIndex = new Array(argsLen).fill().map((_, i) => i)
for (let i = 0; i < secondLen; i++) {
childIndex.forEach((index, j) => {
// console.count('count')
if (i < argChildLen[index]) {
result.push(args[index][i])
} else {
// childIndex.splice(j, 1)
// delete childIndex[j]
}
})
}
if (firstLen > secondLen) {
const firstLenIndex = argChildLen.findIndex(v => v === firstLen)
result = [...result, ...args[firstLenIndex].slice([secondLen])]
}
return result.filter(v => (v != undefined))
}
function arraysLaminated2(...args) {
const result = []
const argLen = args.length
for (let i = 0; i < argLen; i++) {
const item = args[i]
item.forEach((v, j) => {
result[i + j * argLen] = v
})
}
return result.filter(v => (v != undefined))
}
const params = [
new Array(1).fill(1),
new Array(2).fill(2),
new Array(8000).fill(3)
]
// const params = [
// [0, undefined, null, , 0],
// [1, 1, 1, 1, 1],
// [2, 2, 3],
// [3],
// [4, 4, 4, 4, 4, 4],
// new Array(5).fill(5),
// new Array(8).fill(7),
// new Array(800).fill(8),
// new Array(8000).fill(9),
// new Array(3000).fill(10)
// ]
// const result = arraysLaminated(...params)
// console.log(result)
console.time('1')
arraysLaminated(...params)
// console.log(arraysLaminated(...params))
console.timeEnd('1')
console.time('2')
arraysLaminated2(...params)
// console.log(arraysLaminated2(...params))
console.timeEnd('2')
console.log(arraysLaminated(...params))
console.log(arraysLaminated2(...params))
console