JS Built-ins
TypeScriptintermediate

Advanced β€” rotateLeft

πŸ“– Usage Example
rotateLeft([1, 2, 3, 4, 5], 2)   // β†’ [3, 4, 5, 1, 2]

rotateLeft shifts elements left by n positions, wrapping the removed elements to the end.

Advanced: Array Rotation

Challenge: Implement rotateLeft<T>(arr: T[], n: number): T[] shifting elements left by n positions (wraps around).

rotateLeft([1,2,3,4,5], 2)  // β†’ [3,4,5,1,2]
πŸ’‘ Hints (1)
  • β€’ Modulo n by length to handle over-rotation, then slice and spread.