import { isFunction } from './inspect';

// --- Static ---

const from = function () {
  return Array.from(...arguments);
};

// --- Instance ---

const arrayIncludes = (array, value) => array.indexOf(value) !== -1;
const concat = function () {
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
    args[_key] = arguments[_key];
  }
  return Array.prototype.concat.apply([], args);
};

// --- Utilities ---

const createArray = (length, fillFn) => {
  const mapFn = isFunction(fillFn) ? fillFn : () => fillFn;
  return Array.apply(null, {
    length
  }).map(mapFn);
};
const flatten = array => array.reduce((result, item) => concat(result, item), []);
const flattenDeep = array => array.reduce((result, item) => concat(result, Array.isArray(item) ? flattenDeep(item) : item), []);

export { arrayIncludes, concat, createArray, flatten, flattenDeep, from };
