map.js 339 B

123456789101112131415
  1. 'use strict';
  2. module.exports = function map(fn) {
  3. var _this = this;
  4. if (Array.isArray(this.items)) {
  5. return new this.constructor(this.items.map(fn));
  6. }
  7. var collection = {};
  8. Object.keys(this.items).forEach(function (key) {
  9. collection[key] = fn(_this.items[key], key);
  10. });
  11. return new this.constructor(collection);
  12. };