Created
July 30, 2019 03:04
-
-
Save wataruoguchi/e6c454a20956c749aaa159be722036e3 to your computer and use it in GitHub Desktop.
Program for array rotation
This file contains hidden or 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
// Program for array rotation | |
// https://www.geeksforgeeks.org/array-rotation/ | |
function rotate(arr, d, n) { | |
// Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements. | |
const stash = arr.splice(0, d); | |
return arr.concat(stash); | |
} | |
const arr = [1,2,3,4,5,6,7]; | |
const res = rotate(arr, 2, arr.length); | |
console.log(res.join(',') === '3,4,5,6,7,1,2'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment