mirror of
https://github.com/swc-project/swc.git
synced 2024-12-29 16:42:28 +03:00
37 lines
819 B
TypeScript
37 lines
819 B
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/internal/_makeFlat.js
|
|
|
|
|
|
import _isArrayLike from './_isArrayLike.js';
|
|
|
|
|
|
/**
|
|
* `_makeFlat` is a helper function that returns a one-level or fully recursive
|
|
* function based on the flag passed in.
|
|
*
|
|
* @private
|
|
*/
|
|
export default function _makeFlat(recursive) {
|
|
return function flatt(list) {
|
|
var value, jlen, j;
|
|
var result = [];
|
|
var idx = 0;
|
|
var ilen = list.length;
|
|
|
|
while (idx < ilen) {
|
|
if (_isArrayLike(list[idx])) {
|
|
value = recursive ? flatt(list[idx]) : list[idx];
|
|
j = 0;
|
|
jlen = value.length;
|
|
while (j < jlen) {
|
|
result[result.length] = value[j];
|
|
j += 1;
|
|
}
|
|
} else {
|
|
result[result.length] = list[idx];
|
|
}
|
|
idx += 1;
|
|
}
|
|
return result;
|
|
};
|
|
}
|