Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

left rotate array in js

const arr = [1, 2, 3, 4, 5];
function rotateLeft(arr){
  	//remove the first elemnt of array
    let first = arr.shift();
  	//then add into the end of array
    arr.push(first);
    return arr;
}
function rotateRight(arr){
  	//remove the last elemnt of array
    let last =arr.pop();
  	//then add into the first of array
     arr.unshift(last)
    return arr;
}
 
PREVIOUS NEXT
Tagged: #left #rotate #array #js
ADD COMMENT
Topic
Name
6+4 =