source: imaps-frontend/node_modules/core-js/internals/array-unique-by.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.1 KB
Line 
1'use strict';
2var uncurryThis = require('../internals/function-uncurry-this');
3var aCallable = require('../internals/a-callable');
4var isNullOrUndefined = require('../internals/is-null-or-undefined');
5var lengthOfArrayLike = require('../internals/length-of-array-like');
6var toObject = require('../internals/to-object');
7var MapHelpers = require('../internals/map-helpers');
8var iterate = require('../internals/map-iterate');
9
10var Map = MapHelpers.Map;
11var mapHas = MapHelpers.has;
12var mapSet = MapHelpers.set;
13var push = uncurryThis([].push);
14
15// `Array.prototype.uniqueBy` method
16// https://github.com/tc39/proposal-array-unique
17module.exports = function uniqueBy(resolver) {
18 var that = toObject(this);
19 var length = lengthOfArrayLike(that);
20 var result = [];
21 var map = new Map();
22 var resolverFunction = !isNullOrUndefined(resolver) ? aCallable(resolver) : function (value) {
23 return value;
24 };
25 var index, item, key;
26 for (index = 0; index < length; index++) {
27 item = that[index];
28 key = resolverFunction(item);
29 if (!mapHas(map, key)) mapSet(map, key, item);
30 }
31 iterate(map, function (value) {
32 push(result, value);
33 });
34 return result;
35};
Note: See TracBrowser for help on using the repository browser.