Example 1 — Official: Reverse Arrays
The array samples from the Ramda docs, from three items down to none.
console.log(R.reverse([1, 2, 3])); // [3, 2, 1]
console.log(R.reverse([1, 2])); // [2, 1]
console.log(R.reverse([1])); // [1]
console.log(R.reverse([])); // [] How It Works
- Three items. The last item becomes first:
[3, 2, 1]. - Two items. The pair simply swaps places.
- One or zero. There is nothing to swap, so the result looks the same.
- Always new. Even
[1]and[]come back as new arrays, not the originals.
