Example 1 — Official: Replace by Index
The two samples from the Ramda docs: replace index 1, then replace the last item with -1.
console.log(R.update(1, '_', ['a', 'b', 'c'])); // ['a', '_', 'c']
console.log(R.update(-1, '_', ['a', 'b', 'c'])); // ['a', 'b', '_'] How It Works
- Index 1. Indexes start at 0, so index
1is'b'. - Replace.
R.updatecopies the list and puts'_'in that slot. - Index -1. A negative index counts from the end, so
-1is'c'. - Result. Only one slot changes each time; the length stays 3.
