|
1 | 1 | // Insert an item into an array at a specific index (Immutable insertion)
|
2 | 2 | /**
|
3 | | - * |
4 | | - * @param {Array} arr |
5 | | - * @param {Int} index |
6 | | - * @param {*} values |
| 3 | + * |
| 4 | + * @param {Array} array |
| 5 | + * @param {Int} index |
| 6 | + * @param {*} items |
7 | 7 | * @returns arr {New Array}
|
8 | | - * |
9 | | - * @demo let bar = insertAt(arr, 2, 'a', 'b') |
| 8 | + * |
| 9 | + * @demo let bar = insertAt(array, 2, 'a', 'b') |
10 | 10 | */
|
11 | | -export const insertAt = (arr, index) => { |
12 | | - const items = Array.prototype.slice.call(arguments, 2); |
13 | | - |
14 | | - return [].concat(arr.slice(0, index), items, arr.slice(index)); |
15 | | -}; |
| 11 | +export const insertAt = (array, index, ...items) => [...array.slice(0, index), ...items, ...array.slice(index)]; |
0 commit comments