modeling/src/utils/flatten.js

  1. /**
  2. * Flatten the given list of arguments into a single flat array.
  3. * The arguments can be composed of multiple depths of objects and arrays.
  4. * @param {Array} arr - list of arguments
  5. * @returns {Array} a flat list of arguments
  6. * @alias module:modeling/utils.flatten
  7. */
  8. const flatten = (arr) => arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(flatten(val)) : acc.concat(val), [])
  9. module.exports = flatten