Skip to main content

concatenation of array

Link :https://leetcode.com/problems/concatenation-of-array/

solution 1

var getConcatenation = function (nums) {
return [...nums, ...nums];
};

solution 2

return nums.concat(nums);

solution 3

var getConcatenation = function (nums) {
let arr = [];
let limit = nums.length * 2;
let index = 0;
for (let i = 0; i < limit; i++) {
arr[i] = nums[index++];
if (index == nums.length) {
index = 0;
}
}
return arr;
};