Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules / ___dist / chain-able / src / deps / loop / each / baseEach.js
Size: Mime:
"use strict";

const isArrayLike = require("../../is/arrayLike");

const isNill = require("../../is/nullOrUndefined");

const baseForOwn = require("./baseForOwn");
/**
 * The base implementation of `forEach`.
 * @since 5.0.0-beta.6
 * @memberOf loop
 *
 * @param {Array|Object} collection The collection to iterate over.
 * @param {Function} iteratee The function invoked per iteration.
 * @return {Array|Object} Returns `collection`.
 *
 * @see https://github.com/lodash/lodash/blob/master/.internal/baseEach.js
 *
 */


function baseEach(collection, iteratee) {
  if (isNill(collection)) {
    return collection;
  } else if (!isArrayLike(collection)) {
    return baseForOwn(collection, iteratee);
  } // @TODO toObj, length


  const length = collection.length;
  const iterable = Object(collection);
  let index = -1;

  while (++index < length) {
    // stop when they return false
    if (iteratee(iterable[index], index, iterable) === false) {
      break;
    }
  }

  return collection;
}

module.exports = baseEach;