Example 1 — Official revmapIndexed
Reverse the list, then attach indexes from the right.
const revmap = (fn, ary) => R.map(fn, R.reverse(ary));
const revmapIndexed = R.addIndexRight(revmap);
console.log(
revmapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r'])
);
// → ['5-r', '4-a', '3-b', '2-o', '1-o', '0-f'] How It Works
- Reverse.
R.reverseturns the letters intor, a, b, o, o, f. - Wrap.
R.addIndexRight(revmap)starts the index at5. - Label. First visit is
'r'withidx 5→'5-r'. - Countdown. Indexes fall to
0on the final visit ('f').
