massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / array-unique-by.js
1 'use strict';
2 var getBuiltIn = require('../internals/get-built-in');
3 var uncurryThis = require('../internals/function-uncurry-this');
4 var aCallable = require('../internals/a-callable');
5 var lengthOfArrayLike = require('../internals/length-of-array-like');
6 var toObject = require('../internals/to-object');
7 var arraySpeciesCreate = require('../internals/array-species-create');
8
9 var Map = getBuiltIn('Map');
10 var MapPrototype = Map.prototype;
11 var mapForEach = uncurryThis(MapPrototype.forEach);
12 var mapHas = uncurryThis(MapPrototype.has);
13 var mapSet = uncurryThis(MapPrototype.set);
14 var push = uncurryThis([].push);
15
16 // `Array.prototype.uniqueBy` method
17 // https://github.com/tc39/proposal-array-unique
18 module.exports = function uniqueBy(resolver) {
19   var that = toObject(this);
20   var length = lengthOfArrayLike(that);
21   var result = arraySpeciesCreate(that, 0);
22   var map = new Map();
23   var resolverFunction = resolver != null ? aCallable(resolver) : function (value) {
24     return value;
25   };
26   var index, item, key;
27   for (index = 0; index < length; index++) {
28     item = that[index];
29     key = resolverFunction(item);
30     if (!mapHas(map, key)) mapSet(map, key, item);
31   }
32   mapForEach(map, function (value) {
33     push(result, value);
34   });
35   return result;
36 };