• + 0 comments

    A JS solution:

    function rotateLeft(d, arr) {
        // Write your code here
        let rotateArr=new Array(arr.length).fill(null);
        //The start index is from where elements are aligned with arr
        let i=(arr.length - (d % arr.length));
        let j=0;
        while(i <= arr.length - 1) {
            rotateArr[i]=arr[j];
            j++;
            i++;
        }
         i=0;
    		 // the end point is where the alignment begins
        while(i<(arr.length - (d % arr.length))) {
              rotateArr[i]=arr[j];
              j++;
              i++;
             
        }
        return rotateArr;
    }