forked from Tinkoff/utils.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.ts
More file actions
22 lines (20 loc) · 744 Bytes
/
update.ts
File metadata and controls
22 lines (20 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { update } from '../typings/types';
import adjust from './adjust';
import curryN from '../function/curryN';
import always from '../function/always';
/**
* Returns a new copy of the array with the element at the provided index
* replaced with the given value.
*
* @param {Number} idx index
* @param {*} x The value to exist at the given index of the returned array.
* @param {Array} list The source array to be updated.
* @return {Array} A copy of `list` with the value at index `idx` replaced with `x`.
* @example
*
* update(1, 11, [0, 1, 2]); //=> [0, 11, 2]
* update(1)(11)([0, 1, 2]); //=> [0, 11, 2]
*/
export default curryN(3, (idx, x, list) => (
adjust(always(x), idx, list)
)) as typeof update