source: node_modules/ramda-adjunct/lib/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.4 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _ramda = require("ramda");
6var _makeFlat2 = _interopRequireDefault(require("./internal/makeFlat"));
7function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9function _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."); }
10function _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); }
11function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13function _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; }
14var flatten1 = (0, _makeFlat2["default"])(false);
15
16/**
17 * Flattens the list to the specified depth.
18 *
19 * @func flattenDepth
20 * @memberOf RA
21 * @since {@link https://char0n.github.io/ramda-adjunct/2.19.0|v2.19.0}
22 * @category List
23 * @sig Number -> [a] -> [b]
24 * @param {!number} depth The maximum recursion depth
25 * @param {!Array} list The array to flatten
26 * @return {!Array} Returns the new flattened array
27 * @see {@link http://ramdajs.com/docs/#flatten|R.flatten}, {@link http://ramdajs.com/docs/#unnest|R.unnest}
28 * @example
29 *
30 * RA.flattenDepth(
31 * 2,
32 * [1, [2], [3, [4, 5], 6, [[[7], 8]]], 9, 10]
33 * ); //=> [1, 2, 3, 4, 5, 6, [[7], 8], 9, 10];
34 */
35var flattenDepth = (0, _ramda.curry)(function (depth, list) {
36 var currentDept = depth;
37 var flatList = _toConsumableArray(list);
38 while (currentDept > 0) {
39 flatList = flatten1(flatList);
40 currentDept -= 1;
41 }
42 return flatList;
43});
44var _default = flattenDepth;
45exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.