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:
873 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | var _curry2 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry2.js");
|
---|
| 4 |
|
---|
| 5 | var slice =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./slice.js");
|
---|
| 8 | /**
|
---|
| 9 | * Splits a collection into slices of the specified length.
|
---|
| 10 | *
|
---|
| 11 | * @func
|
---|
| 12 | * @memberOf R
|
---|
| 13 | * @since v0.16.0
|
---|
| 14 | * @category List
|
---|
| 15 | * @sig Number -> [a] -> [[a]]
|
---|
| 16 | * @sig Number -> String -> [String]
|
---|
| 17 | * @param {Number} n
|
---|
| 18 | * @param {Array} list
|
---|
| 19 | * @return {Array}
|
---|
| 20 | * @example
|
---|
| 21 | *
|
---|
| 22 | * R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); //=> [[1, 2, 3], [4, 5, 6], [7]]
|
---|
| 23 | * R.splitEvery(3, 'foobarbaz'); //=> ['foo', 'bar', 'baz']
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | var splitEvery =
|
---|
| 28 | /*#__PURE__*/
|
---|
| 29 | _curry2(function splitEvery(n, list) {
|
---|
| 30 | if (n <= 0) {
|
---|
| 31 | throw new Error('First argument to splitEvery must be a positive integer');
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | var result = [];
|
---|
| 35 | var idx = 0;
|
---|
| 36 |
|
---|
| 37 | while (idx < list.length) {
|
---|
| 38 | result.push(slice(idx, idx += n, list));
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | return result;
|
---|
| 42 | });
|
---|
| 43 |
|
---|
| 44 | module.exports = splitEvery; |
---|
Note:
See
TracBrowser
for help on using the repository browser.