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.

16 lines
341 B

4 years ago
  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. };