DEV Community

Discussion on: Not an "Easy" Algorithm: Rotating an Array, Three Ways

Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited

I would have though the shortest version of (1) would be:

    let rotate = (arr,n) => (arr.unshift(...arr.splice(-n % arr.length, n % arr.length)), arr)

Though I guess the splice allocates an array of size n % length