Arrays: Left Rotation

  • + 0 comments

    In js, I tried a different approach. In node.js, it has no difference in performance when it is compared to other approach.

    function rotLeft(a, d) {
        let i = 0, j = i + d;
        let arr = [];
    
        while (i < a.length) {
            if (j < a.length) {
                arr[i] = a[j];
                j++;
            } else {
    		 j = 0;
            }
         i++;
        }
        return arr;
    }