source: node_modules/ramda/es/insert.js

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

Initial commit

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