Reverses the given array when enabled.

Type signature

(enabled: boolean) => <T>(xs: T[]) => T[]

Examples

reverseIf(true)([1, 2, 3, 4, 5]);
// ⇒ [5, 4, 3, 2, 1]
Try in REPL
reverseIf(false)([1, 2, 3, 4, 5]);
// ⇒ [1, 2, 3, 4, 5]
Try in REPL

Questions

  • How to reverse an array without mutating it only when a condition is satisfied?

TypeScript sourceJavaScript source