Dashboard sipadu mbip
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.

keyBy.js 449B

123456789101112131415161718192021
  1. 'use strict';
  2. var nestedValue = require('../helpers/nestedValue');
  3. module.exports = function keyBy(key) {
  4. var collection = {};
  5. if (typeof key === 'function') {
  6. this.items.forEach(function (item) {
  7. collection[key(item)] = item;
  8. });
  9. } else {
  10. this.items.forEach(function (item) {
  11. var keyValue = nestedValue(item, key);
  12. collection[keyValue || ''] = item;
  13. });
  14. }
  15. return new this.constructor(collection);
  16. };