main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
764 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var call = require('../internals/function-call');
|
---|
4 | var iterate = require('../internals/iterate');
|
---|
5 | var isCallable = require('../internals/is-callable');
|
---|
6 | var aCallable = require('../internals/a-callable');
|
---|
7 | var Map = require('../internals/map-helpers').Map;
|
---|
8 |
|
---|
9 | // `Map.keyBy` method
|
---|
10 | // https://github.com/tc39/proposal-collection-methods
|
---|
11 | $({ target: 'Map', stat: true, forced: true }, {
|
---|
12 | keyBy: function keyBy(iterable, keyDerivative) {
|
---|
13 | var C = isCallable(this) ? this : Map;
|
---|
14 | var newMap = new C();
|
---|
15 | aCallable(keyDerivative);
|
---|
16 | var setter = aCallable(newMap.set);
|
---|
17 | iterate(iterable, function (element) {
|
---|
18 | call(setter, newMap, keyDerivative(element), element);
|
---|
19 | });
|
---|
20 | return newMap;
|
---|
21 | }
|
---|
22 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.