Hi sorry if this questions is terrible. I have been working through leetcode and found what I thought to be unexpected behaviour in javascript.
/**
* @param {number[]} nums
* @param {number} k
* @return {void} Do not return anything, modify nums in-place instead.
*/
var rotate = function(nums, k) {
var temparr = nums.splice(0,k)
nums = nums.concat(temparr)
console.log(nums)
};
Your input
[-1,-100,3,99]
2
stdout
[ 3, 99, -1, -100 ]
Output
[3,99]
>Expected
[3,99,-1,-100]
The variable nums = [ 3, 99, -1, -100 ], however the nums out of scope of the function is equal to [3,99], why does this occour and I making some mistake in scope thanks.