Skip to content

Instantly share code, notes, and snippets.

@DylanTackoor
Created March 26, 2019 19:20
Show Gist options
  • Save DylanTackoor/f0c74ca2d52231d083b2f168381954fa to your computer and use it in GitHub Desktop.
Save DylanTackoor/f0c74ca2d52231d083b2f168381954fa to your computer and use it in GitHub Desktop.
HackerRank Solutions
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