esnext.map.key-by.js 619 B

12345678910111213141516171819
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var call = require('../internals/function-call');
  4. var iterate = require('../internals/iterate');
  5. var aCallable = require('../internals/a-callable');
  6. // `Map.keyBy` method
  7. // https://github.com/tc39/proposal-collection-methods
  8. $({ target: 'Map', stat: true, forced: true }, {
  9. keyBy: function keyBy(iterable, keyDerivative) {
  10. var newMap = new this();
  11. aCallable(keyDerivative);
  12. var setter = aCallable(newMap.set);
  13. iterate(iterable, function (element) {
  14. call(setter, newMap, keyDerivative(element), element);
  15. });
  16. return newMap;
  17. }
  18. });