source: node_modules/ramda-adjunct/es/flattenDepth.js

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

Initial commit

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[d24f17c]1function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7import { curry } from 'ramda';
8import _makeFlat from './internal/makeFlat';
9var flatten1 = _makeFlat(false);
10
11/**
12 * Flattens the list to the specified depth.
13 *
14 * @func flattenDepth
15 * @memberOf RA
16 * @since {@link https://char0n.github.io/ramda-adjunct/2.19.0|v2.19.0}
17 * @category List
18 * @sig Number -> [a] -> [b]
19 * @param {!number} depth The maximum recursion depth
20 * @param {!Array} list The array to flatten
21 * @return {!Array} Returns the new flattened array
22 * @see {@link http://ramdajs.com/docs/#flatten|R.flatten}, {@link http://ramdajs.com/docs/#unnest|R.unnest}
23 * @example
24 *
25 * RA.flattenDepth(
26 * 2,
27 * [1, [2], [3, [4, 5], 6, [[[7], 8]]], 9, 10]
28 * ); //=> [1, 2, 3, 4, 5, 6, [[7], 8], 9, 10];
29 */
30var flattenDepth = curry(function (depth, list) {
31 var currentDept = depth;
32 var flatList = _toConsumableArray(list);
33 while (currentDept > 0) {
34 flatList = flatten1(flatList);
35 currentDept -= 1;
36 }
37 return flatList;
38});
39export default flattenDepth;
Note: See TracBrowser for help on using the repository browser.