source: trip-planner-front/node_modules/core-js/internals/array-unique-by.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1'use strict';
2var toLength = require('../internals/to-length');
3var toObject = require('../internals/to-object');
4var getBuiltIn = require('../internals/get-built-in');
5var arraySpeciesCreate = require('../internals/array-species-create');
6
7var push = [].push;
8
9// `Array.prototype.uniqueBy` method
10// https://github.com/tc39/proposal-array-unique
11module.exports = function uniqueBy(resolver) {
12 var that = toObject(this);
13 var length = toLength(that.length);
14 var result = arraySpeciesCreate(that, 0);
15 var Map = getBuiltIn('Map');
16 var map = new Map();
17 var resolverFunction, index, item, key;
18 if (typeof resolver == 'function') resolverFunction = resolver;
19 else if (resolver == null) resolverFunction = function (value) {
20 return value;
21 };
22 else throw new TypeError('Incorrect resolver!');
23 for (index = 0; index < length; index++) {
24 item = that[index];
25 key = resolverFunction(item);
26 if (!map.has(key)) map.set(key, item);
27 }
28 map.forEach(function (value) {
29 push.call(result, value);
30 });
31 return result;
32};
Note: See TracBrowser for help on using the repository browser.