mirror of
https://github.com/swc-project/swc.git
synced 2024-12-26 15:12:08 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
37 lines
891 B
TypeScript
37 lines
891 B
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/splitEvery.js
|
|
|
|
|
|
import _curry2 from './internal/_curry2.js';
|
|
import slice from './slice.js';
|
|
|
|
|
|
/**
|
|
* Splits a collection into slices of the specified length.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.16.0
|
|
* @category List
|
|
* @sig Number -> [a] -> [[a]]
|
|
* @sig Number -> String -> [String]
|
|
* @param {Number} n
|
|
* @param {Array} list
|
|
* @return {Array}
|
|
* @example
|
|
*
|
|
* R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); //=> [[1, 2, 3], [4, 5, 6], [7]]
|
|
* R.splitEvery(3, 'foobarbaz'); //=> ['foo', 'bar', 'baz']
|
|
*/
|
|
var splitEvery = _curry2(function splitEvery(n, list) {
|
|
if (n <= 0) {
|
|
throw new Error('First argument to splitEvery must be a positive integer');
|
|
}
|
|
var result = [];
|
|
var idx = 0;
|
|
while (idx < list.length) {
|
|
result.push(slice(idx, idx += n, list));
|
|
}
|
|
return result;
|
|
});
|
|
export default splitEvery;
|