JSFiddle - React, Tailwind, and code Playground

by Peer Reynders

JavaScript

function rotateLeft(d, arr) {
  const endToBegin = arr.slice(d);
  const beginToEnd = arr.slice(0,d);
  return endToBegin.concat(beginToEnd);
}

const array = [1,2,3,4,5,6]
const rotation = 2
console.log(rotateLeft(rotation,array)) // [3, 4, 5, 6, 1, 2]