You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
551 B

4 years ago
  1. 'use strict';
  2. module.exports = function each(fn) {
  3. var stop = false;
  4. if (Array.isArray(this.items)) {
  5. var length = this.items.length;
  6. for (var index = 0; index < length && !stop; index += 1) {
  7. stop = fn(this.items[index], index, this.items) === false;
  8. }
  9. } else {
  10. var keys = Object.keys(this.items);
  11. var _length = keys.length;
  12. for (var _index = 0; _index < _length && !stop; _index += 1) {
  13. var key = keys[_index];
  14. stop = fn(this.items[key], key, this.items) === false;
  15. }
  16. }
  17. return this;
  18. };