UNPKG

ramda-adjunct

Version:

Ramda Adjunct is the most popular and most comprehensive set of utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.

44 lines (40 loc) 959 B
import isArrayLike from '../isArrayLike'; /** * `makeFlat` is a helper function that returns a one-level or fully recursive * function based on the flag passed in. * * @func makeFlat * @memberOf RA * * @category List * @param {!bool} = should recursively flatten * @param {!Array} = the nested list to be flattened * @return {!Array} = the flattened list * @sig Bool -> List -> List * */ const makeFlat = (recursive) => { return function flatt(list) { let value; let jlen; let j; const result = []; let idx = 0; while (idx < list.length) { 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; }; }; export default makeFlat;