Example 1 — Official Sample and Squares
List the indexes themselves — the sample from the Ramda docs — then square each one.
console.log(R.times(R.identity, 5)); // [0, 1, 2, 3, 4]
console.log(R.times(i => i * i, 5)); // [0, 1, 4, 9, 16] How It Works
- Indexes.
R.timescalls the function with0, 1, 2, 3, 4— five calls forn = 5. - Identity.
R.identityreturns its input unchanged, so the result is the indexes. - Squares.
i => i * iturns each index into its square. - Zero first. Both lists start at 0 because the first index is always 0.
