Can anyone tell me where my JavaScript code is going wrong?


  • 0
    A
    var rotate = function(nums, k) {
    if(nums.length <= 1 || k % nums.length === 0)
        return;
    var temp = nums.splice(nums.length - k, k);
    nums = temp.concat(nums);
    nums = temp.slice();
    };
    

    I imagine it's some sort of scope issue but I'm not really sure how to fix it.. Thanks in advance


  • 0
    Q

    nums is an array and is immutable as a whole object. You can only modify its elements.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.