code: function flatten(a) {
    return a.reduce(function(flat, val) {
      if (val && typeof val.flatten === 'function') {
        flat = flat.concat(val.flatten());
      }
      else if (Array.isArray(val)) {
        flat = flat.concat(flatten(val));
      }
      else {
        flat.push(val);
      }
      return flat;
    });
  }
docs: Based on underscore.js's flatten