2 var $ = require('../internals/export');
3 var toLength = require('../internals/to-length');
4 var toObject = require('../internals/to-object');
5 var getBuiltIn = require('../internals/get-built-in');
6 var arraySpeciesCreate = require('../internals/array-species-create');
7 var addToUnscopables = require('../internals/add-to-unscopables');
11 // `Array.prototype.uniqueBy` method
12 // https://github.com/tc39/proposal-array-unique
13 $({ target: 'Array', proto: true }, {
14 uniqueBy: function uniqueBy(resolver) {
15 var that = toObject(this);
16 var length = toLength(that.length);
17 var result = arraySpeciesCreate(that, 0);
18 var Map = getBuiltIn('Map');
20 var resolverFunction, index, item, key;
21 if (typeof resolver == 'function') resolverFunction = resolver;
22 else if (resolver == null) resolverFunction = function (value) {
25 else throw new TypeError('Incorrect resolver!');
26 for (index = 0; index < length; index++) {
28 key = resolverFunction(item);
29 if (!map.has(key)) map.set(key, item);
31 map.forEach(function (value) {
32 push.call(result, value);
38 addToUnscopables('uniqueBy');