flatten nested array (the nesting can be to any depth).
@param array {Array}
@param i {int}
@returns {Array}
@private
501681
function depthFlatten(array, i) {
  i = i || 0;

  if(i >= array.length)
    return array;

  if(isArray(array[i])) {
    return depthFlatten(array.slice(0,i)
      .concat(array[i], array.slice(i+1)), i);
  }
  return depthFlatten(array, i+1);
}
84075
function flatten(level, map) {
  for (var key in map) {
    var kmap = map[key];
    // we found a definition
    if (kmap._VAL_ || kmap._TAG_) {
      if (kmap._VAL_) {
        flatFields[key] = { level: level, _VAL_ : kmap._VAL_};
      } else {
        flatFields[key] = { level: level, _TAG_ : kmap._TAG_};
      }
    // presumed a level def
    } else {
      var here = level.slice(0);
      here.push(key);
      flatten(here, kmap);
    }
  }
}
143429
protected function flatten($array)
    {
        return array_reduce($array, function ($result, $item) {
            if (! is_array($item)) {
                return array_merge($result, [$item]);
            }

            return array_merge($result, $this->flatten($item));
        }, []);
    }
1058314
private function flattenCallback($array, $depth = INF): array
    {
        $depth = (int) $depth;

        return array_reduce($array, function ($result, $item) use ($depth) {
            $item = $item instanceof self ? $item->all() : $item;

            if (! is_array($item)) {
                return array_merge($result, [$item]);
            } elseif ($depth === 1) {
                return array_merge($result, array_values($item));
            }

            return array_merge($result, self::flattenCallback($item, $depth - 1));
        }, []);
    }
545256
function flattenElementsAr (ar) {
  return ar.reduce((acc, el) => {
    return isArray(el) ? [ ...acc, ...el ] : [ ...acc, el ]
  }, []).filter(notNull) // null means ignore
}
604904
function flatten(array) {
        return array.reduce(function (a, b) {
            return isArray(b) ? a.concat(flatten(b)) : a.concat(b);
        }, []);
    }
1121931
function flatten(array) {
    var result = [], i, n;

    for (i = 0, n = array.length; i < n; i++) {
      if (isArray(array[i])) {
        result = result.concat(flatten(array[i]));
      }
      else {
        result.push(array[i]);
      }
    }

    return result;
  }
539679
public static function flatten($array, $depth = INF)
    {
        $result = [];

        foreach ($array as $item) {
            $item = $item instanceof Collection ? $item->all() : $item;

            if (is_array($item)) {
                if ($depth === 1) {
                    $result = array_merge($result, $item);
                    continue;
                }

                $result = array_merge($result, static::flatten($item, $depth - 1));
                continue;
            }

            $result[] = $item;
        }

        return $result;
    }
574793
def flatten(nested_list: list) -> list:
    """"""
    return list(sorted(filter(lambda y: y is not None,
                              list(map(lambda x: (nested_list.extend(x)  # noqa: T484
                                                  if isinstance(x, list) else x),
                                       nested_list)))))
621355
function flatten(iterable) {
    if (! iterable) return [];

    var array = [];
    for (var i = 0; i < iterable.length; i ++) {
      var current = iterable[i];
      if (typeof(current) === 'string') {
        array.push(current);
      } else if (typeof(current) === 'function') {
        array.push(current);
      } else if (Array.isArray(current)) {
        array = array.concat(flatten(current));
      } else if ((typeof(current) === 'object')
              && (typeof(current.length) === 'number')) {
        // JavaScripts' "arguments" is an object, not an array, and on top of
        // that PhantomJS' own implementation is not iterable... Workaround!
        array = array.concat(flatten(current));
      } else {
        throw new EsquireError("Invalid dependency: " + JSON.stringify(current));
      }
    }
    return array;
  }
142851
function interleave(...arrays) {
  var more = true;
  var n = 0;
  var result = [];
  while (more) {
    more = false;
    for (var array of arrays) {
      if (n >= array.length) continue;
      result.push(array[n]);
      more = true;
    }
    n++;
  }
  return result;
}
909104
function flatten(iterable) {
    if (! iterable) return [];

    var array = [];
    for (var i = 0; i < iterable.length; i ++) {
      var current = iterable[i];
      if (Array.isArray(current)) {
        array = array.concat(flatten(current));
      } else if ((typeof(current) === 'object')
              && (typeof(current.length) === 'number')) {
        // JavaScripts' "arguments" is an object, not an array, and on top of
        // that PhantomJS' own implementation is not iterable... Workaround!
        array = array.concat(flatten(current));
      } else {
        array.push(current);
      }
    }
    return array;
  }
232415
private function _flatten($array)
    {
        if (!is_array($array)) {
            // nothing to do if it's not an array
            return array($array);
        }
        $result = array();
        foreach ($array as $value) {
            // explode the sub-array, and add the parts
            $result = array_merge($result, $this->_flatten($value));
        }
        return $result;
    }
1284882
function _flatten(array) {
        var i = 0,
            result = [],
            queue = [ array ],
            current, ii, ll, item;
        
        while (i < queue.length) {
            current = queue[i]; // current is always an array
            for (ii = 0, ll = current.length; ii < ll; ii++) {
                item = current[ii];
                if (isArray(item)) {
                    queue.push(item);
                } else {
                    result.push(item);
                }
            }
            i++;
        }
        return result;
    }
1254371
function() {
        return [].slice.call(arguments).reduce(function(a, b) {
          return a.concat(Array.isArray(b) ? funcifyr.flatten.apply(null, b) : b);
        }, []);
      }
814201
public function flatten( array $array, $preserve_keys = false ) {
		$return = [];
		array_walk_recursive( $array, function ( $v, $k ) use ( &$return, $preserve_keys ) {
			if ( $preserve_keys ) {
				$return[ $k ] = $v;
			} else {
				$return[] = $v;
			}
		} );

		return $return;
	}
828031
function flatten(arr) {
  if (!isArray(arr)) {
    return arr;
  }
  var result = [];
  each(arr, function (item) {
    if (isArray(item)) {
      each(item, function (subItem) {
        result.push(subItem);
      });
    } else {
      result.push(item);
    }
  });
  return result;
}