source: node_modules/ramda-adjunct/src/flattenDepth.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: 973 bytes
Line 
1import { curry } from 'ramda';
2
3import _makeFlat from './internal/makeFlat';
4
5const flatten1 = _makeFlat(false);
6
7/**
8 * Flattens the list to the specified depth.
9 *
10 * @func flattenDepth
11 * @memberOf RA
12 * @since {@link https://char0n.github.io/ramda-adjunct/2.19.0|v2.19.0}
13 * @category List
14 * @sig Number -> [a] -> [b]
15 * @param {!number} depth The maximum recursion depth
16 * @param {!Array} list The array to flatten
17 * @return {!Array} Returns the new flattened array
18 * @see {@link http://ramdajs.com/docs/#flatten|R.flatten}, {@link http://ramdajs.com/docs/#unnest|R.unnest}
19 * @example
20 *
21 * RA.flattenDepth(
22 * 2,
23 * [1, [2], [3, [4, 5], 6, [[[7], 8]]], 9, 10]
24 * ); //=> [1, 2, 3, 4, 5, 6, [[7], 8], 9, 10];
25 */
26const flattenDepth = curry((depth, list) => {
27 let currentDept = depth;
28 let flatList = [...list];
29
30 while (currentDept > 0) {
31 flatList = flatten1(flatList);
32
33 currentDept -= 1;
34 }
35
36 return flatList;
37});
38
39export default flattenDepth;
Note: See TracBrowser for help on using the repository browser.