substance
Version:
Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing systems.
14 lines (13 loc) • 323 B
JavaScript
import flatten from './flatten'
export default function flattenOften(arr, max) {
if (!(max > 0)) throw new Error("'max' must be a positive number")
let l = arr.length
arr = flatten(arr)
let round = 1
while (round < max && l < arr.length) {
l = arr.length
arr = flatten(arr)
round++
}
return arr
}