.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / array-unique-by.js
1 'use strict';
2 var toLength = require('../internals/to-length');
3 var toObject = require('../internals/to-object');
4 var getBuiltIn = require('../internals/get-built-in');
5 var arraySpeciesCreate = require('../internals/array-species-create');
6
7 var push = [].push;
8
9 // `Array.prototype.uniqueBy` method
10 // https://github.com/tc39/proposal-array-unique
11 module.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 };