From 4cfe2cc75ae1cb058fd8462f800885e8a69bd601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=8D=A3=E6=AD=86?= Date: Wed, 28 Feb 2018 19:03:22 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=8A=A0=20reject,intersection,drop=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lodash.md | 2 +- src/core/lodash.js | 176 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 176 insertions(+), 2 deletions(-) diff --git a/lodash.md b/lodash.md index 39afdfc6a..5528dbd7b 100644 --- a/lodash.md +++ b/lodash.md @@ -1 +1 @@ -lodash core plus=debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random \ No newline at end of file +lodash core plus=debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop \ No newline at end of file diff --git a/src/core/lodash.js b/src/core/lodash.js index 33ba0bcee..e98cff783 100644 --- a/src/core/lodash.js +++ b/src/core/lodash.js @@ -1,7 +1,7 @@ /** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -2321,6 +2321,69 @@ return object != null && key in Object(object); } + /** + * The base implementation of methods like `_.intersection`, without support + * for iteratee shorthands, that accepts an array of arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of shared values. + */ + function baseIntersection(arrays, iteratee, comparator) { + var includes = comparator ? arrayIncludesWith : arrayIncludes, + length = arrays[0].length, + othLength = arrays.length, + othIndex = othLength, + caches = Array(othLength), + maxLength = Infinity, + result = []; + + while (othIndex--) { + var array = arrays[othIndex]; + if (othIndex && iteratee) { + array = arrayMap(array, baseUnary(iteratee)); + } + maxLength = nativeMin(array.length, maxLength); + caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) + ? new SetCache(othIndex && array) + : undefined; + } + array = arrays[0]; + + var index = -1, + seen = caches[0]; + + outer: + while (++index < length && result.length < maxLength) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + value = (comparator || value !== 0) ? value : 0; + if (!(seen + ? cacheHas(seen, computed) + : includes(result, computed, comparator) + )) { + othIndex = othLength; + while (--othIndex) { + var cache = caches[othIndex]; + if (!(cache + ? cacheHas(cache, computed) + : includes(arrays[othIndex], computed, comparator)) + ) { + continue outer; + } + } + if (seen) { + seen.push(computed); + } + result.push(value); + } + } + return result; + } + /** * The base implementation of `_.invert` and `_.invertBy` which inverts * `object` with values transformed by `iteratee` and set by `setter`. @@ -3074,6 +3137,17 @@ }, result); } + /** + * Casts `value` to an empty array if it's not an array like object. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array|Object} Returns the cast array-like object. + */ + function castArrayLikeObject(value) { + return isArrayLikeObject(value) ? value : []; + } + /** * Casts `value` to a path array if it's not one. * @@ -5094,6 +5168,40 @@ return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); } + /** + * Creates a slice of `array` with `n` elements dropped from the beginning. + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.drop([1, 2, 3]); + * // => [2, 3] + * + * _.drop([1, 2, 3], 2); + * // => [3] + * + * _.drop([1, 2, 3], 5); + * // => [] + * + * _.drop([1, 2, 3], 0); + * // => [1, 2, 3] + */ + function drop(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined) ? 1 : toInteger(n); + return baseSlice(array, n < 0 ? 0 : n, length); + } + /** * This method is like `_.find` except that it returns the index of the first * element `predicate` returns truthy for instead of the element itself. @@ -5286,6 +5394,30 @@ return baseIndexOf(array, value, index); } + /** + * Creates an array of unique values that are included in all given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * _.intersection([2, 1], [2, 3]); + * // => [2] + */ + var intersection = baseRest(function(arrays) { + var mapped = arrayMap(arrays, castArrayLikeObject); + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped) + : []; + }); + /** * Gets the last element of `array`. * @@ -6070,6 +6202,45 @@ return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEach); } + /** + * The opposite of `_.filter`; this method returns the elements of `collection` + * that `predicate` does **not** return truthy for. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see _.filter + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': true } + * ]; + * + * _.reject(users, function(o) { return !o.active; }); + * // => objects for ['fred'] + * + * // The `_.matches` iteratee shorthand. + * _.reject(users, { 'age': 40, 'active': true }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.reject(users, ['active', false]); + * // => objects for ['fred'] + * + * // The `_.property` iteratee shorthand. + * _.reject(users, 'active'); + * // => objects for ['barney'] + */ + function reject(collection, predicate) { + var func = isArray(collection) ? arrayFilter : baseFilter; + return func(collection, negate(baseIteratee(predicate, 3))); + } + /** * Gets the size of `collection` by returning its length for array-like * values or the number of own enumerable string keyed properties for objects. @@ -8807,9 +8978,11 @@ lodash.defaults = defaults; lodash.defer = defer; lodash.delay = delay; + lodash.drop = drop; lodash.filter = filter; lodash.flatten = flatten; lodash.flattenDeep = flattenDeep; + lodash.intersection = intersection; lodash.invert = invert; lodash.invertBy = invertBy; lodash.iteratee = iteratee; @@ -8823,6 +8996,7 @@ lodash.once = once; lodash.pick = pick; lodash.range = range; + lodash.reject = reject; lodash.rest = rest; lodash.slice = slice; lodash.sortBy = sortBy; From 9d3181084bbf5e8a4463bfd44dbf50037c3c6ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=8D=A3=E6=AD=86?= Date: Wed, 28 Feb 2018 19:05:36 +0800 Subject: [PATCH 2/3] run grunt --- dist/bundle.js | 176 ++++++++++++++++++++++++++++++++++++++++++++++++- dist/core.js | 176 ++++++++++++++++++++++++++++++++++++++++++++++++- dist/fineui.js | 176 ++++++++++++++++++++++++++++++++++++++++++++++++- utils/utils.js | 176 ++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 700 insertions(+), 4 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 2ccdf4b3b..55d35d169 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -9599,7 +9599,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { })( window );/** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -11919,6 +11919,69 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return object != null && key in Object(object); } + /** + * The base implementation of methods like `_.intersection`, without support + * for iteratee shorthands, that accepts an array of arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of shared values. + */ + function baseIntersection(arrays, iteratee, comparator) { + var includes = comparator ? arrayIncludesWith : arrayIncludes, + length = arrays[0].length, + othLength = arrays.length, + othIndex = othLength, + caches = Array(othLength), + maxLength = Infinity, + result = []; + + while (othIndex--) { + var array = arrays[othIndex]; + if (othIndex && iteratee) { + array = arrayMap(array, baseUnary(iteratee)); + } + maxLength = nativeMin(array.length, maxLength); + caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) + ? new SetCache(othIndex && array) + : undefined; + } + array = arrays[0]; + + var index = -1, + seen = caches[0]; + + outer: + while (++index < length && result.length < maxLength) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + value = (comparator || value !== 0) ? value : 0; + if (!(seen + ? cacheHas(seen, computed) + : includes(result, computed, comparator) + )) { + othIndex = othLength; + while (--othIndex) { + var cache = caches[othIndex]; + if (!(cache + ? cacheHas(cache, computed) + : includes(arrays[othIndex], computed, comparator)) + ) { + continue outer; + } + } + if (seen) { + seen.push(computed); + } + result.push(value); + } + } + return result; + } + /** * The base implementation of `_.invert` and `_.invertBy` which inverts * `object` with values transformed by `iteratee` and set by `setter`. @@ -12672,6 +12735,17 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { }, result); } + /** + * Casts `value` to an empty array if it's not an array like object. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array|Object} Returns the cast array-like object. + */ + function castArrayLikeObject(value) { + return isArrayLikeObject(value) ? value : []; + } + /** * Casts `value` to a path array if it's not one. * @@ -14692,6 +14766,40 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); } + /** + * Creates a slice of `array` with `n` elements dropped from the beginning. + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.drop([1, 2, 3]); + * // => [2, 3] + * + * _.drop([1, 2, 3], 2); + * // => [3] + * + * _.drop([1, 2, 3], 5); + * // => [] + * + * _.drop([1, 2, 3], 0); + * // => [1, 2, 3] + */ + function drop(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined) ? 1 : toInteger(n); + return baseSlice(array, n < 0 ? 0 : n, length); + } + /** * This method is like `_.find` except that it returns the index of the first * element `predicate` returns truthy for instead of the element itself. @@ -14884,6 +14992,30 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return baseIndexOf(array, value, index); } + /** + * Creates an array of unique values that are included in all given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * _.intersection([2, 1], [2, 3]); + * // => [2] + */ + var intersection = baseRest(function(arrays) { + var mapped = arrayMap(arrays, castArrayLikeObject); + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped) + : []; + }); + /** * Gets the last element of `array`. * @@ -15668,6 +15800,45 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEach); } + /** + * The opposite of `_.filter`; this method returns the elements of `collection` + * that `predicate` does **not** return truthy for. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see _.filter + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': true } + * ]; + * + * _.reject(users, function(o) { return !o.active; }); + * // => objects for ['fred'] + * + * // The `_.matches` iteratee shorthand. + * _.reject(users, { 'age': 40, 'active': true }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.reject(users, ['active', false]); + * // => objects for ['fred'] + * + * // The `_.property` iteratee shorthand. + * _.reject(users, 'active'); + * // => objects for ['barney'] + */ + function reject(collection, predicate) { + var func = isArray(collection) ? arrayFilter : baseFilter; + return func(collection, negate(baseIteratee(predicate, 3))); + } + /** * Gets the size of `collection` by returning its length for array-like * values or the number of own enumerable string keyed properties for objects. @@ -18405,9 +18576,11 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.defaults = defaults; lodash.defer = defer; lodash.delay = delay; + lodash.drop = drop; lodash.filter = filter; lodash.flatten = flatten; lodash.flattenDeep = flattenDeep; + lodash.intersection = intersection; lodash.invert = invert; lodash.invertBy = invertBy; lodash.iteratee = iteratee; @@ -18421,6 +18594,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.once = once; lodash.pick = pick; lodash.range = range; + lodash.reject = reject; lodash.rest = rest; lodash.slice = slice; lodash.sortBy = sortBy; diff --git a/dist/core.js b/dist/core.js index efbd02986..c16fa0090 100644 --- a/dist/core.js +++ b/dist/core.js @@ -9599,7 +9599,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { })( window );/** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -11919,6 +11919,69 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return object != null && key in Object(object); } + /** + * The base implementation of methods like `_.intersection`, without support + * for iteratee shorthands, that accepts an array of arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of shared values. + */ + function baseIntersection(arrays, iteratee, comparator) { + var includes = comparator ? arrayIncludesWith : arrayIncludes, + length = arrays[0].length, + othLength = arrays.length, + othIndex = othLength, + caches = Array(othLength), + maxLength = Infinity, + result = []; + + while (othIndex--) { + var array = arrays[othIndex]; + if (othIndex && iteratee) { + array = arrayMap(array, baseUnary(iteratee)); + } + maxLength = nativeMin(array.length, maxLength); + caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) + ? new SetCache(othIndex && array) + : undefined; + } + array = arrays[0]; + + var index = -1, + seen = caches[0]; + + outer: + while (++index < length && result.length < maxLength) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + value = (comparator || value !== 0) ? value : 0; + if (!(seen + ? cacheHas(seen, computed) + : includes(result, computed, comparator) + )) { + othIndex = othLength; + while (--othIndex) { + var cache = caches[othIndex]; + if (!(cache + ? cacheHas(cache, computed) + : includes(arrays[othIndex], computed, comparator)) + ) { + continue outer; + } + } + if (seen) { + seen.push(computed); + } + result.push(value); + } + } + return result; + } + /** * The base implementation of `_.invert` and `_.invertBy` which inverts * `object` with values transformed by `iteratee` and set by `setter`. @@ -12672,6 +12735,17 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { }, result); } + /** + * Casts `value` to an empty array if it's not an array like object. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array|Object} Returns the cast array-like object. + */ + function castArrayLikeObject(value) { + return isArrayLikeObject(value) ? value : []; + } + /** * Casts `value` to a path array if it's not one. * @@ -14692,6 +14766,40 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); } + /** + * Creates a slice of `array` with `n` elements dropped from the beginning. + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.drop([1, 2, 3]); + * // => [2, 3] + * + * _.drop([1, 2, 3], 2); + * // => [3] + * + * _.drop([1, 2, 3], 5); + * // => [] + * + * _.drop([1, 2, 3], 0); + * // => [1, 2, 3] + */ + function drop(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined) ? 1 : toInteger(n); + return baseSlice(array, n < 0 ? 0 : n, length); + } + /** * This method is like `_.find` except that it returns the index of the first * element `predicate` returns truthy for instead of the element itself. @@ -14884,6 +14992,30 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return baseIndexOf(array, value, index); } + /** + * Creates an array of unique values that are included in all given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * _.intersection([2, 1], [2, 3]); + * // => [2] + */ + var intersection = baseRest(function(arrays) { + var mapped = arrayMap(arrays, castArrayLikeObject); + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped) + : []; + }); + /** * Gets the last element of `array`. * @@ -15668,6 +15800,45 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEach); } + /** + * The opposite of `_.filter`; this method returns the elements of `collection` + * that `predicate` does **not** return truthy for. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see _.filter + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': true } + * ]; + * + * _.reject(users, function(o) { return !o.active; }); + * // => objects for ['fred'] + * + * // The `_.matches` iteratee shorthand. + * _.reject(users, { 'age': 40, 'active': true }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.reject(users, ['active', false]); + * // => objects for ['fred'] + * + * // The `_.property` iteratee shorthand. + * _.reject(users, 'active'); + * // => objects for ['barney'] + */ + function reject(collection, predicate) { + var func = isArray(collection) ? arrayFilter : baseFilter; + return func(collection, negate(baseIteratee(predicate, 3))); + } + /** * Gets the size of `collection` by returning its length for array-like * values or the number of own enumerable string keyed properties for objects. @@ -18405,9 +18576,11 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.defaults = defaults; lodash.defer = defer; lodash.delay = delay; + lodash.drop = drop; lodash.filter = filter; lodash.flatten = flatten; lodash.flattenDeep = flattenDeep; + lodash.intersection = intersection; lodash.invert = invert; lodash.invertBy = invertBy; lodash.iteratee = iteratee; @@ -18421,6 +18594,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.once = once; lodash.pick = pick; lodash.range = range; + lodash.reject = reject; lodash.rest = rest; lodash.slice = slice; lodash.sortBy = sortBy; diff --git a/dist/fineui.js b/dist/fineui.js index 0944c9c3f..a28fdef87 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -9800,7 +9800,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { })( window );/** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -12120,6 +12120,69 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return object != null && key in Object(object); } + /** + * The base implementation of methods like `_.intersection`, without support + * for iteratee shorthands, that accepts an array of arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of shared values. + */ + function baseIntersection(arrays, iteratee, comparator) { + var includes = comparator ? arrayIncludesWith : arrayIncludes, + length = arrays[0].length, + othLength = arrays.length, + othIndex = othLength, + caches = Array(othLength), + maxLength = Infinity, + result = []; + + while (othIndex--) { + var array = arrays[othIndex]; + if (othIndex && iteratee) { + array = arrayMap(array, baseUnary(iteratee)); + } + maxLength = nativeMin(array.length, maxLength); + caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) + ? new SetCache(othIndex && array) + : undefined; + } + array = arrays[0]; + + var index = -1, + seen = caches[0]; + + outer: + while (++index < length && result.length < maxLength) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + value = (comparator || value !== 0) ? value : 0; + if (!(seen + ? cacheHas(seen, computed) + : includes(result, computed, comparator) + )) { + othIndex = othLength; + while (--othIndex) { + var cache = caches[othIndex]; + if (!(cache + ? cacheHas(cache, computed) + : includes(arrays[othIndex], computed, comparator)) + ) { + continue outer; + } + } + if (seen) { + seen.push(computed); + } + result.push(value); + } + } + return result; + } + /** * The base implementation of `_.invert` and `_.invertBy` which inverts * `object` with values transformed by `iteratee` and set by `setter`. @@ -12873,6 +12936,17 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { }, result); } + /** + * Casts `value` to an empty array if it's not an array like object. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array|Object} Returns the cast array-like object. + */ + function castArrayLikeObject(value) { + return isArrayLikeObject(value) ? value : []; + } + /** * Casts `value` to a path array if it's not one. * @@ -14893,6 +14967,40 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); } + /** + * Creates a slice of `array` with `n` elements dropped from the beginning. + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.drop([1, 2, 3]); + * // => [2, 3] + * + * _.drop([1, 2, 3], 2); + * // => [3] + * + * _.drop([1, 2, 3], 5); + * // => [] + * + * _.drop([1, 2, 3], 0); + * // => [1, 2, 3] + */ + function drop(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined) ? 1 : toInteger(n); + return baseSlice(array, n < 0 ? 0 : n, length); + } + /** * This method is like `_.find` except that it returns the index of the first * element `predicate` returns truthy for instead of the element itself. @@ -15085,6 +15193,30 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return baseIndexOf(array, value, index); } + /** + * Creates an array of unique values that are included in all given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * _.intersection([2, 1], [2, 3]); + * // => [2] + */ + var intersection = baseRest(function(arrays) { + var mapped = arrayMap(arrays, castArrayLikeObject); + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped) + : []; + }); + /** * Gets the last element of `array`. * @@ -15869,6 +16001,45 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEach); } + /** + * The opposite of `_.filter`; this method returns the elements of `collection` + * that `predicate` does **not** return truthy for. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see _.filter + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': true } + * ]; + * + * _.reject(users, function(o) { return !o.active; }); + * // => objects for ['fred'] + * + * // The `_.matches` iteratee shorthand. + * _.reject(users, { 'age': 40, 'active': true }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.reject(users, ['active', false]); + * // => objects for ['fred'] + * + * // The `_.property` iteratee shorthand. + * _.reject(users, 'active'); + * // => objects for ['barney'] + */ + function reject(collection, predicate) { + var func = isArray(collection) ? arrayFilter : baseFilter; + return func(collection, negate(baseIteratee(predicate, 3))); + } + /** * Gets the size of `collection` by returning its length for array-like * values or the number of own enumerable string keyed properties for objects. @@ -18606,9 +18777,11 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.defaults = defaults; lodash.defer = defer; lodash.delay = delay; + lodash.drop = drop; lodash.filter = filter; lodash.flatten = flatten; lodash.flattenDeep = flattenDeep; + lodash.intersection = intersection; lodash.invert = invert; lodash.invertBy = invertBy; lodash.iteratee = iteratee; @@ -18622,6 +18795,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.once = once; lodash.pick = pick; lodash.range = range; + lodash.reject = reject; lodash.rest = rest; lodash.slice = slice; lodash.sortBy = sortBy; diff --git a/utils/utils.js b/utils/utils.js index 2f623cbf9..0320ab342 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,7 +1,7 @@ /** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -2321,6 +2321,69 @@ return object != null && key in Object(object); } + /** + * The base implementation of methods like `_.intersection`, without support + * for iteratee shorthands, that accepts an array of arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of shared values. + */ + function baseIntersection(arrays, iteratee, comparator) { + var includes = comparator ? arrayIncludesWith : arrayIncludes, + length = arrays[0].length, + othLength = arrays.length, + othIndex = othLength, + caches = Array(othLength), + maxLength = Infinity, + result = []; + + while (othIndex--) { + var array = arrays[othIndex]; + if (othIndex && iteratee) { + array = arrayMap(array, baseUnary(iteratee)); + } + maxLength = nativeMin(array.length, maxLength); + caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) + ? new SetCache(othIndex && array) + : undefined; + } + array = arrays[0]; + + var index = -1, + seen = caches[0]; + + outer: + while (++index < length && result.length < maxLength) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + value = (comparator || value !== 0) ? value : 0; + if (!(seen + ? cacheHas(seen, computed) + : includes(result, computed, comparator) + )) { + othIndex = othLength; + while (--othIndex) { + var cache = caches[othIndex]; + if (!(cache + ? cacheHas(cache, computed) + : includes(arrays[othIndex], computed, comparator)) + ) { + continue outer; + } + } + if (seen) { + seen.push(computed); + } + result.push(value); + } + } + return result; + } + /** * The base implementation of `_.invert` and `_.invertBy` which inverts * `object` with values transformed by `iteratee` and set by `setter`. @@ -3074,6 +3137,17 @@ }, result); } + /** + * Casts `value` to an empty array if it's not an array like object. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array|Object} Returns the cast array-like object. + */ + function castArrayLikeObject(value) { + return isArrayLikeObject(value) ? value : []; + } + /** * Casts `value` to a path array if it's not one. * @@ -5094,6 +5168,40 @@ return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); } + /** + * Creates a slice of `array` with `n` elements dropped from the beginning. + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.drop([1, 2, 3]); + * // => [2, 3] + * + * _.drop([1, 2, 3], 2); + * // => [3] + * + * _.drop([1, 2, 3], 5); + * // => [] + * + * _.drop([1, 2, 3], 0); + * // => [1, 2, 3] + */ + function drop(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined) ? 1 : toInteger(n); + return baseSlice(array, n < 0 ? 0 : n, length); + } + /** * This method is like `_.find` except that it returns the index of the first * element `predicate` returns truthy for instead of the element itself. @@ -5286,6 +5394,30 @@ return baseIndexOf(array, value, index); } + /** + * Creates an array of unique values that are included in all given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * _.intersection([2, 1], [2, 3]); + * // => [2] + */ + var intersection = baseRest(function(arrays) { + var mapped = arrayMap(arrays, castArrayLikeObject); + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped) + : []; + }); + /** * Gets the last element of `array`. * @@ -6070,6 +6202,45 @@ return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEach); } + /** + * The opposite of `_.filter`; this method returns the elements of `collection` + * that `predicate` does **not** return truthy for. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see _.filter + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': true } + * ]; + * + * _.reject(users, function(o) { return !o.active; }); + * // => objects for ['fred'] + * + * // The `_.matches` iteratee shorthand. + * _.reject(users, { 'age': 40, 'active': true }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.reject(users, ['active', false]); + * // => objects for ['fred'] + * + * // The `_.property` iteratee shorthand. + * _.reject(users, 'active'); + * // => objects for ['barney'] + */ + function reject(collection, predicate) { + var func = isArray(collection) ? arrayFilter : baseFilter; + return func(collection, negate(baseIteratee(predicate, 3))); + } + /** * Gets the size of `collection` by returning its length for array-like * values or the number of own enumerable string keyed properties for objects. @@ -8807,9 +8978,11 @@ lodash.defaults = defaults; lodash.defer = defer; lodash.delay = delay; + lodash.drop = drop; lodash.filter = filter; lodash.flatten = flatten; lodash.flattenDeep = flattenDeep; + lodash.intersection = intersection; lodash.invert = invert; lodash.invertBy = invertBy; lodash.iteratee = iteratee; @@ -8823,6 +8996,7 @@ lodash.once = once; lodash.pick = pick; lodash.range = range; + lodash.reject = reject; lodash.rest = rest; lodash.slice = slice; lodash.sortBy = sortBy; From 17cf61a56020b01f0b3a860ee7c23fc22e752438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=8D=A3=E6=AD=86?= Date: Thu, 1 Mar 2018 11:49:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=8A=A0=20countBy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/bundle.js | 89 +++++++++++++++++++++++++++++++++++++++++++++- dist/core.js | 89 +++++++++++++++++++++++++++++++++++++++++++++- dist/fineui.js | 89 +++++++++++++++++++++++++++++++++++++++++++++- lodash.md | 2 +- src/core/lodash.js | 89 +++++++++++++++++++++++++++++++++++++++++++++- utils/utils.js | 89 +++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 441 insertions(+), 6 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 55d35d169..53abe15d1 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -9599,7 +9599,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { })( window );/** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -9891,6 +9891,27 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return func.apply(thisArg, args); } + /** + * A specialized version of `baseAggregator` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function arrayAggregator(array, setter, iteratee, accumulator) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + var value = array[index]; + setter(accumulator, value, iteratee(value), array); + } + return accumulator; + } + /** * A specialized version of `_.forEach` for arrays without support for * iteratee shorthands. @@ -11474,6 +11495,24 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return -1; } + /** + * Aggregates elements of `collection` on `accumulator` with keys transformed + * by `iteratee` and values set by `setter`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function baseAggregator(collection, setter, iteratee, accumulator) { + baseEach(collection, function(value, key, collection) { + setter(accumulator, value, iteratee(value), collection); + }); + return accumulator; + } + /** * The base implementation of `_.assign` without support for multiple sources * or `customizer` functions. @@ -13073,6 +13112,23 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return copyObject(source, getSymbolsIn(source), object); } + /** + * Creates a function like `_.groupBy`. + * + * @private + * @param {Function} setter The function to set accumulator values. + * @param {Function} [initializer] The accumulator object initializer. + * @returns {Function} Returns the new aggregator function. + */ + function createAggregator(setter, initializer) { + return function(collection, iteratee) { + var func = isArray(collection) ? arrayAggregator : baseAggregator, + accumulator = initializer ? initializer() : {}; + + return func(collection, setter, baseIteratee(iteratee, 2), accumulator); + }; + } + /** * Creates a function like `_.assign`. * @@ -15545,6 +15601,36 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { /*------------------------------------------------------------------------*/ + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the number of times the key was returned by `iteratee`. The + * iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.countBy([6.1, 4.2, 6.3], Math.floor); + * // => { '4': 1, '6': 2 } + * + * // The `_.property` iteratee shorthand. + * _.countBy(['one', 'two', 'three'], 'length'); + * // => { '3': 2, '5': 1 } + */ + var countBy = createAggregator(function(result, value, key) { + if (hasOwnProperty.call(result, key)) { + ++result[key]; + } else { + baseAssignValue(result, key, 1); + } + }); + /** * Checks if `predicate` returns truthy for **all** elements of `collection`. * Iteration is stopped once `predicate` returns falsey. The predicate is @@ -18571,6 +18657,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.chain = chain; lodash.compact = compact; lodash.concat = concat; + lodash.countBy = countBy; lodash.create = create; lodash.debounce = debounce; lodash.defaults = defaults; diff --git a/dist/core.js b/dist/core.js index c16fa0090..88a59f14f 100644 --- a/dist/core.js +++ b/dist/core.js @@ -9599,7 +9599,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { })( window );/** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -9891,6 +9891,27 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return func.apply(thisArg, args); } + /** + * A specialized version of `baseAggregator` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function arrayAggregator(array, setter, iteratee, accumulator) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + var value = array[index]; + setter(accumulator, value, iteratee(value), array); + } + return accumulator; + } + /** * A specialized version of `_.forEach` for arrays without support for * iteratee shorthands. @@ -11474,6 +11495,24 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return -1; } + /** + * Aggregates elements of `collection` on `accumulator` with keys transformed + * by `iteratee` and values set by `setter`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function baseAggregator(collection, setter, iteratee, accumulator) { + baseEach(collection, function(value, key, collection) { + setter(accumulator, value, iteratee(value), collection); + }); + return accumulator; + } + /** * The base implementation of `_.assign` without support for multiple sources * or `customizer` functions. @@ -13073,6 +13112,23 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return copyObject(source, getSymbolsIn(source), object); } + /** + * Creates a function like `_.groupBy`. + * + * @private + * @param {Function} setter The function to set accumulator values. + * @param {Function} [initializer] The accumulator object initializer. + * @returns {Function} Returns the new aggregator function. + */ + function createAggregator(setter, initializer) { + return function(collection, iteratee) { + var func = isArray(collection) ? arrayAggregator : baseAggregator, + accumulator = initializer ? initializer() : {}; + + return func(collection, setter, baseIteratee(iteratee, 2), accumulator); + }; + } + /** * Creates a function like `_.assign`. * @@ -15545,6 +15601,36 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { /*------------------------------------------------------------------------*/ + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the number of times the key was returned by `iteratee`. The + * iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.countBy([6.1, 4.2, 6.3], Math.floor); + * // => { '4': 1, '6': 2 } + * + * // The `_.property` iteratee shorthand. + * _.countBy(['one', 'two', 'three'], 'length'); + * // => { '3': 2, '5': 1 } + */ + var countBy = createAggregator(function(result, value, key) { + if (hasOwnProperty.call(result, key)) { + ++result[key]; + } else { + baseAssignValue(result, key, 1); + } + }); + /** * Checks if `predicate` returns truthy for **all** elements of `collection`. * Iteration is stopped once `predicate` returns falsey. The predicate is @@ -18571,6 +18657,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.chain = chain; lodash.compact = compact; lodash.concat = concat; + lodash.countBy = countBy; lodash.create = create; lodash.debounce = debounce; lodash.defaults = defaults; diff --git a/dist/fineui.js b/dist/fineui.js index a28fdef87..3402a900c 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -9800,7 +9800,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { })( window );/** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -10092,6 +10092,27 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return func.apply(thisArg, args); } + /** + * A specialized version of `baseAggregator` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function arrayAggregator(array, setter, iteratee, accumulator) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + var value = array[index]; + setter(accumulator, value, iteratee(value), array); + } + return accumulator; + } + /** * A specialized version of `_.forEach` for arrays without support for * iteratee shorthands. @@ -11675,6 +11696,24 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return -1; } + /** + * Aggregates elements of `collection` on `accumulator` with keys transformed + * by `iteratee` and values set by `setter`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function baseAggregator(collection, setter, iteratee, accumulator) { + baseEach(collection, function(value, key, collection) { + setter(accumulator, value, iteratee(value), collection); + }); + return accumulator; + } + /** * The base implementation of `_.assign` without support for multiple sources * or `customizer` functions. @@ -13274,6 +13313,23 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return copyObject(source, getSymbolsIn(source), object); } + /** + * Creates a function like `_.groupBy`. + * + * @private + * @param {Function} setter The function to set accumulator values. + * @param {Function} [initializer] The accumulator object initializer. + * @returns {Function} Returns the new aggregator function. + */ + function createAggregator(setter, initializer) { + return function(collection, iteratee) { + var func = isArray(collection) ? arrayAggregator : baseAggregator, + accumulator = initializer ? initializer() : {}; + + return func(collection, setter, baseIteratee(iteratee, 2), accumulator); + }; + } + /** * Creates a function like `_.assign`. * @@ -15746,6 +15802,36 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { /*------------------------------------------------------------------------*/ + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the number of times the key was returned by `iteratee`. The + * iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.countBy([6.1, 4.2, 6.3], Math.floor); + * // => { '4': 1, '6': 2 } + * + * // The `_.property` iteratee shorthand. + * _.countBy(['one', 'two', 'three'], 'length'); + * // => { '3': 2, '5': 1 } + */ + var countBy = createAggregator(function(result, value, key) { + if (hasOwnProperty.call(result, key)) { + ++result[key]; + } else { + baseAssignValue(result, key, 1); + } + }); + /** * Checks if `predicate` returns truthy for **all** elements of `collection`. * Iteration is stopped once `predicate` returns falsey. The predicate is @@ -18772,6 +18858,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.chain = chain; lodash.compact = compact; lodash.concat = concat; + lodash.countBy = countBy; lodash.create = create; lodash.debounce = debounce; lodash.defaults = defaults; diff --git a/lodash.md b/lodash.md index 5528dbd7b..49a00ce30 100644 --- a/lodash.md +++ b/lodash.md @@ -1 +1 @@ -lodash core plus=debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop \ No newline at end of file +lodash core plus=debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy \ No newline at end of file diff --git a/src/core/lodash.js b/src/core/lodash.js index e98cff783..c0dd7459a 100644 --- a/src/core/lodash.js +++ b/src/core/lodash.js @@ -1,7 +1,7 @@ /** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -293,6 +293,27 @@ return func.apply(thisArg, args); } + /** + * A specialized version of `baseAggregator` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function arrayAggregator(array, setter, iteratee, accumulator) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + var value = array[index]; + setter(accumulator, value, iteratee(value), array); + } + return accumulator; + } + /** * A specialized version of `_.forEach` for arrays without support for * iteratee shorthands. @@ -1876,6 +1897,24 @@ return -1; } + /** + * Aggregates elements of `collection` on `accumulator` with keys transformed + * by `iteratee` and values set by `setter`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function baseAggregator(collection, setter, iteratee, accumulator) { + baseEach(collection, function(value, key, collection) { + setter(accumulator, value, iteratee(value), collection); + }); + return accumulator; + } + /** * The base implementation of `_.assign` without support for multiple sources * or `customizer` functions. @@ -3475,6 +3514,23 @@ return copyObject(source, getSymbolsIn(source), object); } + /** + * Creates a function like `_.groupBy`. + * + * @private + * @param {Function} setter The function to set accumulator values. + * @param {Function} [initializer] The accumulator object initializer. + * @returns {Function} Returns the new aggregator function. + */ + function createAggregator(setter, initializer) { + return function(collection, iteratee) { + var func = isArray(collection) ? arrayAggregator : baseAggregator, + accumulator = initializer ? initializer() : {}; + + return func(collection, setter, baseIteratee(iteratee, 2), accumulator); + }; + } + /** * Creates a function like `_.assign`. * @@ -5947,6 +6003,36 @@ /*------------------------------------------------------------------------*/ + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the number of times the key was returned by `iteratee`. The + * iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.countBy([6.1, 4.2, 6.3], Math.floor); + * // => { '4': 1, '6': 2 } + * + * // The `_.property` iteratee shorthand. + * _.countBy(['one', 'two', 'three'], 'length'); + * // => { '3': 2, '5': 1 } + */ + var countBy = createAggregator(function(result, value, key) { + if (hasOwnProperty.call(result, key)) { + ++result[key]; + } else { + baseAssignValue(result, key, 1); + } + }); + /** * Checks if `predicate` returns truthy for **all** elements of `collection`. * Iteration is stopped once `predicate` returns falsey. The predicate is @@ -8973,6 +9059,7 @@ lodash.chain = chain; lodash.compact = compact; lodash.concat = concat; + lodash.countBy = countBy; lodash.create = create; lodash.debounce = debounce; lodash.defaults = defaults; diff --git a/utils/utils.js b/utils/utils.js index 0320ab342..7642e6de1 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,7 +1,7 @@ /** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -293,6 +293,27 @@ return func.apply(thisArg, args); } + /** + * A specialized version of `baseAggregator` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function arrayAggregator(array, setter, iteratee, accumulator) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + var value = array[index]; + setter(accumulator, value, iteratee(value), array); + } + return accumulator; + } + /** * A specialized version of `_.forEach` for arrays without support for * iteratee shorthands. @@ -1876,6 +1897,24 @@ return -1; } + /** + * Aggregates elements of `collection` on `accumulator` with keys transformed + * by `iteratee` and values set by `setter`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function baseAggregator(collection, setter, iteratee, accumulator) { + baseEach(collection, function(value, key, collection) { + setter(accumulator, value, iteratee(value), collection); + }); + return accumulator; + } + /** * The base implementation of `_.assign` without support for multiple sources * or `customizer` functions. @@ -3475,6 +3514,23 @@ return copyObject(source, getSymbolsIn(source), object); } + /** + * Creates a function like `_.groupBy`. + * + * @private + * @param {Function} setter The function to set accumulator values. + * @param {Function} [initializer] The accumulator object initializer. + * @returns {Function} Returns the new aggregator function. + */ + function createAggregator(setter, initializer) { + return function(collection, iteratee) { + var func = isArray(collection) ? arrayAggregator : baseAggregator, + accumulator = initializer ? initializer() : {}; + + return func(collection, setter, baseIteratee(iteratee, 2), accumulator); + }; + } + /** * Creates a function like `_.assign`. * @@ -5947,6 +6003,36 @@ /*------------------------------------------------------------------------*/ + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the number of times the key was returned by `iteratee`. The + * iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.countBy([6.1, 4.2, 6.3], Math.floor); + * // => { '4': 1, '6': 2 } + * + * // The `_.property` iteratee shorthand. + * _.countBy(['one', 'two', 'three'], 'length'); + * // => { '3': 2, '5': 1 } + */ + var countBy = createAggregator(function(result, value, key) { + if (hasOwnProperty.call(result, key)) { + ++result[key]; + } else { + baseAssignValue(result, key, 1); + } + }); + /** * Checks if `predicate` returns truthy for **all** elements of `collection`. * Iteration is stopped once `predicate` returns falsey. The predicate is @@ -8973,6 +9059,7 @@ lodash.chain = chain; lodash.compact = compact; lodash.concat = concat; + lodash.countBy = countBy; lodash.create = create; lodash.debounce = debounce; lodash.defaults = defaults;