simontonsoftware / s-libs

A collection of libraries for any of javascript, rxjs, or angular.
MIT License
43 stars 5 forks source link

[micro-dash] Flatten fails with large arrays #46

Closed ersimont closed 3 years ago

ersimont commented 3 years ago

With a large array flatten() fails with a stack overflow error.

A (much bigger) implementation that works:

function flatten(array: any[]) {
  const result: any[] = [];
  for (const element of array) {
    if (Array.isArray(element)) {
      for (const inner of element) {
        result.push(inner);
      }
    } else {
      result.push(element);
    }
  }
  return result;
}