From 3c2795b816f404fa87b1ad4ca6218df7a0d9bad9 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 4 Mar 2017 23:26:27 -0800 Subject: [PATCH] Remove `baseForOwn` from several modules. --- findKey.js | 16 ++++++++++++---- forOwn.js | 7 +++---- forOwnRight.js | 11 ++++++++--- functions.js | 10 ++++------ invert.js | 4 +--- invertBy.js | 5 +---- mapKeys.js | 3 +-- mapValues.js | 3 +-- 8 files changed, 31 insertions(+), 28 deletions(-) diff --git a/findKey.js b/findKey.js index 45dd63d98..eefbade76 100644 --- a/findKey.js +++ b/findKey.js @@ -1,6 +1,3 @@ -import baseFindKey from './.internal/baseFindKey.js' -import baseForOwn from './.internal/baseForOwn.js' - /** * This method is like `find` except that it returns the key of the first * element `predicate` returns truthy for instead of the element itself. @@ -24,7 +21,18 @@ import baseForOwn from './.internal/baseForOwn.js' * // => 'barney' (iteration order is not guaranteed) */ function findKey(object, predicate) { - return baseFindKey(object, predicate, baseForOwn) + let result + if (object == null) { + return result + } + Object.keys(object).some((key) => { + const value = object[key] + if (predicate(value, key, object)) { + result = value + return true + } + }) + return result } export default findKey diff --git a/forOwn.js b/forOwn.js index 220ff6031..a7d3f55e6 100644 --- a/forOwn.js +++ b/forOwn.js @@ -1,5 +1,3 @@ -import baseForOwn from './.internal/baseForOwn.js' - /** * Iterates over own enumerable string keyed properties of an object and * invokes `iteratee` for each property. The iteratee is invoked with three @@ -10,7 +8,6 @@ import baseForOwn from './.internal/baseForOwn.js' * @category Object * @param {Object} object The object to iterate over. * @param {Function} iteratee The function invoked per iteration. - * @returns {Object} Returns `object`. * @see forEach, forEachRight, forIn, forInRight, forOwnRight * @example * @@ -27,7 +24,9 @@ import baseForOwn from './.internal/baseForOwn.js' * // => Logs 'a' then 'b' (iteration order is not guaranteed). */ function forOwn(object, iteratee) { - return object && baseForOwn(object, iteratee) + if (object != null) { + Object.keys(Object(object)).forEach((key) => iteratee(object[key], key, object)) + } } export default forOwn diff --git a/forOwnRight.js b/forOwnRight.js index 9c33c21bd..e54264cc4 100644 --- a/forOwnRight.js +++ b/forOwnRight.js @@ -1,5 +1,3 @@ -import baseForOwnRight from './.internal/baseForOwnRight.js' - /** * This method is like `forOwn` except that it iterates over properties of * `object` in the opposite order. @@ -25,7 +23,14 @@ import baseForOwnRight from './.internal/baseForOwnRight.js' * // => Logs 'b' then 'a' assuming `forOwn` logs 'a' then 'b'. */ function forOwnRight(object, iteratee) { - return object && baseForOwnRight(object, iteratee) + if (object == null) { + return + } + const props = Object.keys(object) + const length = props.length + while (length--) { + iteratee(object[props[length]], iteratee, object) + } } export default forOwnRight diff --git a/functions.js b/functions.js index 0b417786e..3242c835a 100644 --- a/functions.js +++ b/functions.js @@ -1,6 +1,3 @@ -import arrayFilter from './arrayFilter.js' -import keys from './keys.js' - /** * Creates an array of function property names from own enumerable properties * of `object`. @@ -23,9 +20,10 @@ import keys from './keys.js' * // => ['a', 'b'] */ function functions(object) { - return object == null - ? [] - : arrayFilter(keys(object), key => typeof object[key] == 'function') + if (object == null) { + return [] + } + return Object.keys(object).filter((key) => typeof object[key] == 'function') } export default functions diff --git a/invert.js b/invert.js index e37150101..3cb243054 100644 --- a/invert.js +++ b/invert.js @@ -1,5 +1,3 @@ -import baseForOwn from './.internal/baseForOwn.js' - /** * Creates an object composed of the inverted keys and values of `object`. * If `object` contains duplicate values, subsequent values overwrite @@ -18,7 +16,7 @@ import baseForOwn from './.internal/baseForOwn.js' */ function invert(object) { const result = {} - baseForOwn(object, (value, key) => { + Object.keys(object).forEach((value, key) => { result[value] = key }) return result diff --git a/invertBy.js b/invertBy.js index cdafa7d2f..e7bd56149 100644 --- a/invertBy.js +++ b/invertBy.js @@ -1,5 +1,3 @@ -import baseForOwn from './.internal/baseForOwn.js' - /** Used to check objects for own properties. */ const hasOwnProperty = Object.prototype.hasOwnProperty @@ -24,8 +22,7 @@ const hasOwnProperty = Object.prototype.hasOwnProperty */ function invertBy(object, iteratee) { const result = {} - baseForOwn(object, (value, key) => { - + Object.keys(object).forEach((value, key) => { value = iteratee(value) if (hasOwnProperty.call(result, value)) { result[value].push(key) diff --git a/mapKeys.js b/mapKeys.js index 6b0571d39..394dc1e20 100644 --- a/mapKeys.js +++ b/mapKeys.js @@ -1,5 +1,4 @@ import baseAssignValue from './.internal/baseAssignValue.js' -import baseForOwn from './.internal/baseForOwn.js' /** * The opposite of `mapValues` this method creates an object with the @@ -22,7 +21,7 @@ import baseForOwn from './.internal/baseForOwn.js' */ function mapKeys(object, iteratee) { const result = {} - baseForOwn(object, (value, key, object) => { + Object.keys(object).forEach((value, key, object) => { baseAssignValue(result, iteratee(value, key, object), value) }) return result diff --git a/mapValues.js b/mapValues.js index 5d62bac56..ec96e59db 100644 --- a/mapValues.js +++ b/mapValues.js @@ -1,5 +1,4 @@ import baseAssignValue from './.internal/baseAssignValue.js' -import baseForOwn from './.internal/baseForOwn.js' /** * Creates an object with the same keys as `object` and values generated @@ -25,7 +24,7 @@ import baseForOwn from './.internal/baseForOwn.js' */ function mapValues(object, iteratee) { const result = {} - baseForOwn(object, (value, key, object) => { + Object.keys(object).forEach((value, key, object) => { baseAssignValue(result, key, iteratee(value, key, object)) }) return result