Is the following a close representation of how concat might be implemented on the Array object?
Array.prototype.myConcat = function(...args) {
let arr = [...this];
for (let arg of args) {
// allow one level of unnesting
if (!Array.isArray(arg)) arg = [arg,]
for (let subarg of arg) {
arr.push(subarg);
}
}
return arr;
};
let x1 = [1,2,3].myConcat('hello', 'new', [1,2,3], [1,2,[3,4]]);
let x2 = [1,2,3].concat('hello', 'new', [1,2,3], [1,2,[3,4]]);
console.log(x1, x2, JSON.stringify(x1) === JSON.stringify(x2));