'use strict';

module.exports = function each(fn) {
  let stop = false;

  if (Array.isArray(this.items)) {
    this.items.forEach((item, key, array) => {
      if (!stop) {
        const output = fn(item, key, array);

        if (output === false) {
          stop = true;
        }
      }
    });
  } else {
    Object.keys(this.items).forEach((key) => {
      if (!stop) {
        const output = fn(this.items[key], key, this.items);

        if (output === false) {
          stop = true;
        }
      }
    });
  }

  return this;
};

'use strict';

module.exports = function each(fn) {
  let stop = false;

  if (Array.isArray(this.items)) {
    const { length } = this.items;

    for (let i = 0; i < length && !stop; i++) {
      stop = fn(this.items[i], i, this.items) === false;
    }
  } else {
    const keys = Object.keys(this.items);
    const { length } = keys;

    for (let i = 0; i < length && !stop; i++) {
      const key = keys[i];

      stop = fn(this.items[key], key, this.items) === false;
    }
  }

  return this;
};

Exit from for loop to reduce execution time
Exit from for loop to reduce execution time

Using `forEach` doesn't give an option to break the loop so implement it ourselves then use `stop` to break from it.

I also like to support the asynchronous each? will it break library?