UNPKG

rambda

Version:

Lightweight and faster alternative to Ramda with included TS definitions

16 lines (12 loc) 381 B
import { cloneList } from './_internals/cloneList.js' export function modifyItemAtIndex(index, replaceFn) { return list => { const actualIndex = index < 0 ? list.length + index : index if (index >= list.length || actualIndex < 0) { return list } const clone = cloneList(list) clone[actualIndex] = replaceFn(clone[actualIndex]) return clone } }