Rotate Array

December 13, 2021

This is my implementation for rotating an array/acting similar to a linked list in javascript

Link LeetCode Link

alt text

var rotate = function(nums, k) { tmp = []; x = 0; for(i=0; i<nums.length;i++){ x = ( ((nums.length - (k%nums.length))+i)%(nums.length) //This is very roundabout ); tmp.push(nums[x]); } //console.log(tmp) for(i2 = 0; i2<tmp.length; i2++){ nums[i2] = tmp[i2]; } //console.log(nums); };

The interesting part is that we search through a modulus in a cumbersome roundabout manner