Array left Rotation


In this article i am sharing the hacker rank problem (Left Rotation Problem):
A left rotation operation on an array of size shifts each of the array's elements unit to the left. Given an integer, , rotate the array that many steps left and return the result.

Example
d=2

 arr=[1,2,3,4,5] 

After rotations,

 arr=[3,4,5,1,2] 
let arr = [1,2,3,4,5,6]
let d=2;
function rotateLeft(arr,d)
{
  for(let i=1;i<=d; i++)
  {
    let temp=arr[0];
    for(let j=0; j<arr.length; j++)
    {
        if(j==arr.length-1)
            arr[j] = temp;
        else
        arr[j] = arr[j+1];
            
    }
  }
  return arr
}

console.log(rotateLeft(arr,d)) // resutl: [3,4,5,6,1,2]