1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 1× 2× 2× 2× 2× 2× 1× 1× 1× 2× | import flatten from './flatten' export default function flattenOften(arr, max) { Iif (!(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 } |