source: node_modules/ramda-adjunct/es/internal/makeFlat.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 966 bytes
Line 
1import isArrayLike from '../isArrayLike';
2
3/**
4 * `makeFlat` is a helper function that returns a one-level or fully recursive
5 * function based on the flag passed in.
6 *
7 * @func makeFlat
8 * @memberOf RA
9 *
10 * @category List
11 * @param {!bool} = should recursively flatten
12 * @param {!Array} = the nested list to be flattened
13 * @return {!Array} = the flattened list
14 * @sig Bool -> List -> List
15 *
16 */
17var makeFlat = function makeFlat(recursive) {
18 return function flatt(list) {
19 var value;
20 var jlen;
21 var j;
22 var result = [];
23 var idx = 0;
24 while (idx < list.length) {
25 if (isArrayLike(list[idx])) {
26 value = recursive ? flatt(list[idx]) : list[idx];
27 j = 0;
28 jlen = value.length;
29 while (j < jlen) {
30 result[result.length] = value[j];
31 j += 1;
32 }
33 } else {
34 result[result.length] = list[idx];
35 }
36 idx += 1;
37 }
38 return result;
39 };
40};
41export default makeFlat;
Note: See TracBrowser for help on using the repository browser.