Arrays: Left Rotation

  • + 0 comments

    I was thinking to do the same but thought not gonna do this with arithmetic so I just looped twice.

    let result = [];
    for(let i = shiftAmount; i < array.length; i++){
        result.push(array[i]);
    }
    for(let i = 0; i < shiftAmount; i++){
        result.push(array[i]);
    }
    return result;