This code returns an array that consists of two copies of the input array.
Can you review this algorithm?
//input: [1, 2, 3] output: [1, 2, 3, 1, 2, 3]
function duplicate(arr) {
let copy = [];
for(let i = 0; i < arr.length; i++) {
copy.push(arr[i])
}
return copy.concat(arr)
}
return arr.concat(arr)\$\endgroup\$return [...arr, ...arr];\$\endgroup\$