all files / util/ flattenOften.js

90.91% Statements 10/11
75% Branches 3/4
100% Functions 1/1
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14       
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
}