Skip to content

Commit 3c2795b

Browse files
committed
Remove baseForOwn from several modules.
1 parent 17f7069 commit 3c2795b

8 files changed

+31
-28
lines changed

findKey.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import baseFindKey from './.internal/baseFindKey.js'
2-
import baseForOwn from './.internal/baseForOwn.js'
3-
41
/**
52
* This method is like `find` except that it returns the key of the first
63
* element `predicate` returns truthy for instead of the element itself.
@@ -24,7 +21,18 @@ import baseForOwn from './.internal/baseForOwn.js'
2421
* // => 'barney' (iteration order is not guaranteed)
2522
*/
2623
function findKey(object, predicate) {
27-
return baseFindKey(object, predicate, baseForOwn)
24+
let result
25+
if (object == null) {
26+
return result
27+
}
28+
Object.keys(object).some((key) => {
29+
const value = object[key]
30+
if (predicate(value, key, object)) {
31+
result = value
32+
return true
33+
}
34+
})
35+
return result
2836
}
2937

3038
export default findKey

forOwn.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import baseForOwn from './.internal/baseForOwn.js'
2-
31
/**
42
* Iterates over own enumerable string keyed properties of an object and
53
* invokes `iteratee` for each property. The iteratee is invoked with three
@@ -10,7 +8,6 @@ import baseForOwn from './.internal/baseForOwn.js'
108
* @category Object
119
* @param {Object} object The object to iterate over.
1210
* @param {Function} iteratee The function invoked per iteration.
13-
* @returns {Object} Returns `object`.
1411
* @see forEach, forEachRight, forIn, forInRight, forOwnRight
1512
* @example
1613
*
@@ -27,7 +24,9 @@ import baseForOwn from './.internal/baseForOwn.js'
2724
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
2825
*/
2926
function forOwn(object, iteratee) {
30-
return object && baseForOwn(object, iteratee)
27+
if (object != null) {
28+
Object.keys(Object(object)).forEach((key) => iteratee(object[key], key, object))
29+
}
3130
}
3231

3332
export default forOwn

forOwnRight.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import baseForOwnRight from './.internal/baseForOwnRight.js'
2-
31
/**
42
* This method is like `forOwn` except that it iterates over properties of
53
* `object` in the opposite order.
@@ -25,7 +23,14 @@ import baseForOwnRight from './.internal/baseForOwnRight.js'
2523
* // => Logs 'b' then 'a' assuming `forOwn` logs 'a' then 'b'.
2624
*/
2725
function forOwnRight(object, iteratee) {
28-
return object && baseForOwnRight(object, iteratee)
26+
if (object == null) {
27+
return
28+
}
29+
const props = Object.keys(object)
30+
const length = props.length
31+
while (length--) {
32+
iteratee(object[props[length]], iteratee, object)
33+
}
2934
}
3035

3136
export default forOwnRight

functions.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import arrayFilter from './arrayFilter.js'
2-
import keys from './keys.js'
3-
41
/**
52
* Creates an array of function property names from own enumerable properties
63
* of `object`.
@@ -23,9 +20,10 @@ import keys from './keys.js'
2320
* // => ['a', 'b']
2421
*/
2522
function functions(object) {
26-
return object == null
27-
? []
28-
: arrayFilter(keys(object), key => typeof object[key] == 'function')
23+
if (object == null) {
24+
return []
25+
}
26+
return Object.keys(object).filter((key) => typeof object[key] == 'function')
2927
}
3028

3129
export default functions

invert.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import baseForOwn from './.internal/baseForOwn.js'
2-
31
/**
42
* Creates an object composed of the inverted keys and values of `object`.
53
* If `object` contains duplicate values, subsequent values overwrite
@@ -18,7 +16,7 @@ import baseForOwn from './.internal/baseForOwn.js'
1816
*/
1917
function invert(object) {
2018
const result = {}
21-
baseForOwn(object, (value, key) => {
19+
Object.keys(object).forEach((value, key) => {
2220
result[value] = key
2321
})
2422
return result

invertBy.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import baseForOwn from './.internal/baseForOwn.js'
2-
31
/** Used to check objects for own properties. */
42
const hasOwnProperty = Object.prototype.hasOwnProperty
53

@@ -24,8 +22,7 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
2422
*/
2523
function invertBy(object, iteratee) {
2624
const result = {}
27-
baseForOwn(object, (value, key) => {
28-
25+
Object.keys(object).forEach((value, key) => {
2926
value = iteratee(value)
3027
if (hasOwnProperty.call(result, value)) {
3128
result[value].push(key)

mapKeys.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import baseAssignValue from './.internal/baseAssignValue.js'
2-
import baseForOwn from './.internal/baseForOwn.js'
32

43
/**
54
* The opposite of `mapValues` this method creates an object with the
@@ -22,7 +21,7 @@ import baseForOwn from './.internal/baseForOwn.js'
2221
*/
2322
function mapKeys(object, iteratee) {
2423
const result = {}
25-
baseForOwn(object, (value, key, object) => {
24+
Object.keys(object).forEach((value, key, object) => {
2625
baseAssignValue(result, iteratee(value, key, object), value)
2726
})
2827
return result

mapValues.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import baseAssignValue from './.internal/baseAssignValue.js'
2-
import baseForOwn from './.internal/baseForOwn.js'
32

43
/**
54
* Creates an object with the same keys as `object` and values generated
@@ -25,7 +24,7 @@ import baseForOwn from './.internal/baseForOwn.js'
2524
*/
2625
function mapValues(object, iteratee) {
2726
const result = {}
28-
baseForOwn(object, (value, key, object) => {
27+
Object.keys(object).forEach((value, key, object) => {
2928
baseAssignValue(result, key, iteratee(value, key, object))
3029
})
3130
return result

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy