πŸ“Š JavaScript
Q. What will be the output of the following code snippet?
Code:
function solve(arr, rotations){
 if(rotations == 0) return arr;
 for(let i = 0; i < rotations; i++){
   let element = arr.pop();
   arr.unshift(element);
 }
 return arr;
}
// solve([44, 1, 22, 111], 5);
  • (A) [111, 44, 1, 22]
  • (B) [44, 1, 22, 111]
  • (C) [111, 44, 1, 22]
  • (D) [1, 22, 111, 44]
πŸ’¬ Discuss
βœ… Correct Answer: (A) [111, 44, 1, 22]

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
273
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Admin
Publisher
πŸ“ˆ
85%
Success Rate