Array: Left Rotation (better)

In this example below you will see how to do a Array: Left Rotation (better) with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by elaboratecon, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright elaboratecon ©
  • HTML
  • CSS
  • JavaScript
    

/*Downloaded from https://www.codeseek.co/elaboratecon/array-left-rotation-better-rzyvdR */
    


/*Downloaded from https://www.codeseek.co/elaboratecon/array-left-rotation-better-rzyvdR */
    let k = 54
let a = [1, 2, 3, 4, 5]



for (var i = 0; i < k; i++) {
  // Removes first element
  var temp = a.shift()
  // Appends it to end
  a.push(temp)
}
console.log(a.join(' '))

Comments