main
Last change
on this file since e48199a was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | var _checkForMethod =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_checkForMethod.js");
|
---|
4 |
|
---|
5 | var _curry2 =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_curry2.js");
|
---|
8 | /**
|
---|
9 | * Creates a new list with the separator interposed between elements.
|
---|
10 | *
|
---|
11 | * Dispatches to the `intersperse` method of the second argument, if present.
|
---|
12 | *
|
---|
13 | * @func
|
---|
14 | * @memberOf R
|
---|
15 | * @since v0.14.0
|
---|
16 | * @category List
|
---|
17 | * @sig a -> [a] -> [a]
|
---|
18 | * @param {*} separator The element to add to the list.
|
---|
19 | * @param {Array} list The list to be interposed.
|
---|
20 | * @return {Array} The new list.
|
---|
21 | * @example
|
---|
22 | *
|
---|
23 | * R.intersperse('a', ['b', 'n', 'n', 's']); //=> ['b', 'a', 'n', 'a', 'n', 'a', 's']
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | var intersperse =
|
---|
28 | /*#__PURE__*/
|
---|
29 | _curry2(
|
---|
30 | /*#__PURE__*/
|
---|
31 | _checkForMethod('intersperse', function intersperse(separator, list) {
|
---|
32 | var out = [];
|
---|
33 | var idx = 0;
|
---|
34 | var length = list.length;
|
---|
35 |
|
---|
36 | while (idx < length) {
|
---|
37 | if (idx === length - 1) {
|
---|
38 | out.push(list[idx]);
|
---|
39 | } else {
|
---|
40 | out.push(list[idx], separator);
|
---|
41 | }
|
---|
42 |
|
---|
43 | idx += 1;
|
---|
44 | }
|
---|
45 |
|
---|
46 | return out;
|
---|
47 | }));
|
---|
48 |
|
---|
49 | module.exports = intersperse; |
---|
Note:
See
TracBrowser
for help on using the repository browser.