/**
* 根据depth递归减少array的嵌套层级
* Recursively flatten `array` up to `depth` times.
* @param {Array} The array to flatten
* @param {number} [depth=1] The maximum recursion depth.
* @returns {Array} Returns the new flattened array.
* @example
*
* var array = [1, [2, [3, [4]], 5]]
* flattenDepth(array, 1)
* // => [1, 2, [3, [4]], 5]
* flattenDepth(array, 2)
* // => [1, 2, 3, [4], 5]
*/
const NAN = 0 / 0
const INFINITY = 1 / 0
const symbolTag = "[object Symbol]"
const MAX_INTEGER = Number.MAX_VALUE || 1.7976931348623157e308
function isObjectLike(value) {
return typeof value == "object" && value !== null
}
function isSymbol(value) {
return (
typeof value === "symbol" ||
(isObjectLike(value) && Object.prototype.toString.call(value) === symbolTag)
)
}
function toNu
根据depth递归减少array的嵌套层级
最新推荐文章于 2021-07-03 01:42:26 发布
本文探讨如何通过递归方法有效减少数组的嵌套层级,提高数据处理效率,适用于处理大量深度嵌套的数据结构。
摘要由CSDN通过智能技术生成