Duplicating an array 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 &lt; arr.length; i++) {
  copy.push(arr[i])
  }
 return copy.concat(arr)
 }
The alternative approaches in the comments return arr.concat(arr); and return [...arr, ...arr]; are good replacements.

However, if you wrote this as part of a course, you should consider the following:


Your indentation is off, this is rule 1 in writing code: indent it
You are missing a semicolon after copy.push(arr[i])
In such a small function, I would have declared i up top in that let statement