Created
March 26, 2019 19:20
-
-
Save DylanTackoor/f0c74ca2d52231d083b2f168381954fa to your computer and use it in GitHub Desktop.
HackerRank Solutions
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
const a = [1, 2, 3, 4, 5] | |
const d = 4 | |
function rotLeft(array, shift) { | |
const newArr = [] | |
for (let index = 0; index < array.length; index++) { | |
const newIndex = Math.abs(index - shift + array.length) | |
newArr[newIndex] = array[index] | |
} | |
return newArr | |
} | |
const rotated = rotLeft(a, d) | |
console.log(rotated) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment