JS Built-ins
TypeScriptbeginner

Generics β€” tail<T>

πŸ“– Usage Example
function tail<T>(arr: T[]): T[] { return arr.slice(1) }
tail([1, 2, 3])   // β†’ [2, 3]
tail([1])         // β†’ []

tail<T> returns all elements except the first, preserving the generic element type.

Generics: tail<T>

Challenge: Implement tail<T>(arr: T[]): T[] returning all elements except the first.

tail([1, 2, 3])  // β†’ [2, 3]
tail([1])        // β†’ []
πŸ’‘ Hints (1)
  • β€’ arr.slice(1) starts at index 1 and goes to the end.