From d40c5d3de80a3e7435e3bfc7fe7077fb2d5c88aa Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 9 Nov 2015 17:26:19 -0800 Subject: [PATCH] Add `createSet`. --- lodash.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index 8dc8eb223..da9260ba4 100644 --- a/lodash.js +++ b/lodash.js @@ -3378,8 +3378,7 @@ * @returns {Array} Returns the new duplicate free array. */ function baseUniq(array, iteratee, comparator) { - var seen, - index = -1, + var index = -1, includes = arrayIncludes, length = array.length, isCommon = true, @@ -3391,6 +3390,10 @@ includes = arrayIncludesWith; } else if (length >= LARGE_ARRAY_SIZE) { + var set = createSet(array); + if (set) { + return setToArray(set); + } isCommon = false; includes = cacheHas; seen = new SetCache; @@ -4227,6 +4230,17 @@ }; } + /** + * Creates a set of `values`. + * + * @private + * @param {Array} values The values to add to the set. + * @returns {Object} Returns the new set. + */ + var createSet = !(Set && new Set([1, 2]).size === 2) ? noop : function(values) { + return new Set(values); + }; + /** * Creates a function that either curries or invokes `func` with optional * `this` binding and partially applied arguments.