gajus / table

Formats data into a string table.
Other
894 stars 77 forks source link

utils.flatten is prone to stack overflow #222

Open evil-shrike opened 9 months ago

evil-shrike commented 9 months ago

Givenflatten function from utils.js:

const flatten = (array) => {
    return [].concat(...array);
};

The problem with the current implementation is that it's prone to stack overflow ("Maximum call stack size exceeded") as the spread operator puts all arguments on stack.

I'd suggest changing it to a less fancy but more stable implementation:

const flatten = (array) => {
  let dest = [];
  const len = array.length
  for(let i = 0; i < len; i++){
      dest.push(...array[i])
  }
  return dest;
};