Skip to content

Instantly share code, notes, and snippets.

@harryWonder
Created July 21, 2022 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harryWonder/8e659326f6b2ad929d13b28af49c78f0 to your computer and use it in GitHub Desktop.
Save harryWonder/8e659326f6b2ad929d13b28af49c78f0 to your computer and use it in GitHub Desktop.
Left Rotations
function leftRotations(a = [], d = 5) {
const input = a;
const arrayLength = input.length;
const rotation = d;
for (let index = 0; index < arrayLength; index++) {
if ((index + 1) <= rotation) {
let arrayIndex = input.shift();
input.push(arrayIndex);
} else {
break;
}
}
console.log(input);
return input;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment