Last active
March 14, 2021 00:09
-
-
Save bgoonz/4e2a040cd94006bb887a77a68f4287b9 to your computer and use it in GitHub Desktop.
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
let rotateRight = function (array, num) { | |
let result = array.slice(0); | |
for (let i = 0; i < num; i++) { | |
let ele = result.pop(); | |
result.unshift(ele); | |
} | |
return result; | |
}; | |
//let arr = ["a", "b", "c", "d", "e"]; | |
console.log(rotateRight(arr, 2)); | |
//["d", "e", "a", "b", "c"]; | |
console.log(arr); | |
["a", "b", "c", "d", "e"]; | |
let animals = ["wombat", "koala", "opossum", "kangaroo"]; | |
console.log(rotateRight(animals, 3)); | |
//["koala", "opossum", "kangaroo", "wombat"]; | |
console.log(animals); | |
//["wombat", "koala", "opossum", "kangaroo"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment