source: node_modules/ramda/src/insert.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 963 bytes
Line 
1var _curry3 =
2/*#__PURE__*/
3require("./internal/_curry3.js");
4/**
5 * Inserts the supplied element into the list, at the specified `index`. _Note that
6
7 * this is not destructive_: it returns a copy of the list with the changes.
8 * <small>No lists have been harmed in the application of this function.</small>
9 *
10 * @func
11 * @memberOf R
12 * @since v0.2.2
13 * @category List
14 * @sig Number -> a -> [a] -> [a]
15 * @param {Number} index The position to insert the element
16 * @param {*} elt The element to insert into the Array
17 * @param {Array} list The list to insert into
18 * @return {Array} A new Array with `elt` inserted at `index`.
19 * @example
20 *
21 * R.insert(2, 'x', [1,2,3,4]); //=> [1,2,'x',3,4]
22 */
23
24
25var insert =
26/*#__PURE__*/
27_curry3(function insert(idx, elt, list) {
28 idx = idx < list.length && idx >= 0 ? idx : list.length;
29 var result = Array.prototype.slice.call(list, 0);
30 result.splice(idx, 0, elt);
31 return result;
32});
33
34module.exports = insert;
Note: See TracBrowser for help on using the repository browser.