95% solution with easiest explanation
the first solution which usually come to our mind is remove the last item, then add it at first. like this: \n\n\nvar rotate = function(nums, k) {\n\tfor(let i 
the first solution which usually come to our mind is remove the last item, then add it at first. like this: \n\n```\nvar rotate = function(nums, k) {\n\tfor(let i = 0; i<k; i++){\n\t\t nums.unshift(nums.pop());\n\t}\n   \n};\n```\nBut, it has some time issue.\n\nThe alternative solution is using remainder. if k is less then the length of nums array, then it will remove k elements from the end, and add those at first. but, if k is greater than the length of nums array, then only the remainder of k % nums.length will be removed from the last and those will be added at the first. As a example ; if k is 2 and nums.length is 3, then 2 element will be removed from the end and those will be add at the first. this will be same as if we rotate 2 times. \n\nbut, if length is 2 but k is 3, and if we then rotate the array 3 times in pen and paper, we will see that after final rotation the scene will be like - only 1 element removed from the end and added at first. here 1 is the remainder of k % nums.length. This will be the case everytime whenever k is greater than nums.length. So the final solution will be- \n\n\n\n```\nvar rotate = function(nums, k) {\n    return nums.unshift(...nums.splice(-k % nums.length));\n};\n```\n\nhere, by using splice we remove the element from the last, splice gives us an array output. thats why we using spread operator while we wanna unshift all element which we spliced from the end.
['Python', 'JavaScript']