mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Implement baseEach and baseEachRight since createBaseFor is gone.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import createBaseFor from './createBaseFor.js'
|
||||
|
||||
/**
|
||||
* The base implementation of `baseForOwn` which iterates over `object`
|
||||
* properties returned by `keysFunc` and invokes `iteratee` for each property.
|
||||
@@ -11,6 +9,19 @@ import createBaseFor from './createBaseFor.js'
|
||||
* @param {Function} keysFunc The function to get the keys of `object`.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
const baseFor = createBaseFor()
|
||||
function baseFor(object, iteratee, keysFunc) {
|
||||
const iterable = Object(object)
|
||||
const props = keysFunc(object)
|
||||
let { length } = props;
|
||||
let index = -1;
|
||||
|
||||
while (length--) {
|
||||
const key = props[++index];
|
||||
if (iteratee(iterable[key], key, iterable) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object
|
||||
}
|
||||
|
||||
export default baseFor
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import createBaseFor from './createBaseFor.js'
|
||||
|
||||
/**
|
||||
* This function is like `baseFor` except that it iterates over properties
|
||||
* in the opposite order.
|
||||
@@ -10,6 +8,18 @@ import createBaseFor from './createBaseFor.js'
|
||||
* @param {Function} keysFunc The function to get the keys of `object`.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
const baseForRight = createBaseFor(true)
|
||||
function baseForRight(object, iteratee, keysFunc) {
|
||||
const iterable = Object(object)
|
||||
const props = keysFunc(object)
|
||||
let { length } = props;
|
||||
|
||||
while (length--) {
|
||||
const key = props[length];
|
||||
if (iteratee(iterable[key], key, iterable) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object
|
||||
}
|
||||
|
||||
export default baseForRight
|
||||
|
||||
Reference in New Issue
Block a user