Created
July 21, 2022 21:51
-
-
Save harryWonder/8e659326f6b2ad929d13b28af49c78f0 to your computer and use it in GitHub Desktop.
Left Rotations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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