Use a For Loop, but Avoid an Infinite Loop (JavaScript)
Intuition\nIt seems like using a simple for loop to push into to the nums array could do the trick, but using i < nums.length for the condition causes an infini
# Intuition\nIt seems like using a simple for loop to push into to the nums array could do the trick, but using i < nums.length for the condition causes an infinite loop because nums gets longer with each number pushed into it. \n\n# Approach\nTo prevent an infinite loop, you can first store the original length of the nums array argument. Then, set the loop to run only for that definite length of items. When the loop runs, it adds each value of the original nums array to the end and then stops. \n\n# Complexity\n- Time complexity:\nO(n) because you iterate through each item in the nums array. \n\n- Space complexity:\nO(n) because the amount of space you need depends on the number of items in the nums array. \n\n# Code\n```\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar getConcatenation = function(nums) {\n    const len = nums.length\n    for (let i = 0; i < len; i++) {\n        nums.push(nums[i])\n    }\n    return nums\n};\n```
['JavaScript']