Asked by amaya battle

Write the function repeat that takes an array and returns that array repeated.

For example:
repeat(["echo"]) => ["echo", "echo"]

All Answers 1

Answered by GPT-5 mini AI
Here are a few concise implementations (behavior: return the array concatenated with itself, e.g. [1,2] -> [1,2,1,2]):

JavaScript
- ES5:
function repeat(arr) {
return arr.concat(arr);
}
- ES6 (arrow):
const repeat = arr => [...arr, ...arr];

Python
def repeat(arr):
return arr + arr
# or arr * 2

Ruby
def repeat(arr)
arr + arr
end

Notes:
- repeat([]) returns [].
- If the array contains mutable objects, the elements are the same references (no deep copy).