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:
990 bytes
|
Line | |
---|
1 | import _checkForMethod from "./internal/_checkForMethod.js";
|
---|
2 | import _curry2 from "./internal/_curry2.js";
|
---|
3 | /**
|
---|
4 | * Creates a new list with the separator interposed between elements.
|
---|
5 | *
|
---|
6 | * Dispatches to the `intersperse` method of the second argument, if present.
|
---|
7 | *
|
---|
8 | * @func
|
---|
9 | * @memberOf R
|
---|
10 | * @since v0.14.0
|
---|
11 | * @category List
|
---|
12 | * @sig a -> [a] -> [a]
|
---|
13 | * @param {*} separator The element to add to the list.
|
---|
14 | * @param {Array} list The list to be interposed.
|
---|
15 | * @return {Array} The new list.
|
---|
16 | * @example
|
---|
17 | *
|
---|
18 | * R.intersperse('a', ['b', 'n', 'n', 's']); //=> ['b', 'a', 'n', 'a', 'n', 'a', 's']
|
---|
19 | */
|
---|
20 |
|
---|
21 | var intersperse =
|
---|
22 | /*#__PURE__*/
|
---|
23 | _curry2(
|
---|
24 | /*#__PURE__*/
|
---|
25 | _checkForMethod('intersperse', function intersperse(separator, list) {
|
---|
26 | var out = [];
|
---|
27 | var idx = 0;
|
---|
28 | var length = list.length;
|
---|
29 |
|
---|
30 | while (idx < length) {
|
---|
31 | if (idx === length - 1) {
|
---|
32 | out.push(list[idx]);
|
---|
33 | } else {
|
---|
34 | out.push(list[idx], separator);
|
---|
35 | }
|
---|
36 |
|
---|
37 | idx += 1;
|
---|
38 | }
|
---|
39 |
|
---|
40 | return out;
|
---|
41 | }));
|
---|
42 |
|
---|
43 | export default intersperse; |
---|
Note:
See
TracBrowser
for help on using the repository browser.