createBaseFor.js 704 B

123456789101112131415161718192021222324252627
  1. import toObject from './toObject';
  2. /**
  3. * Creates a base function for `_.forIn` or `_.forInRight`.
  4. *
  5. * @private
  6. * @param {boolean} [fromRight] Specify iterating from right to left.
  7. * @returns {Function} Returns the new base function.
  8. */
  9. function createBaseFor(fromRight) {
  10. return function(object, iteratee, keysFunc) {
  11. var iterable = toObject(object),
  12. props = keysFunc(object),
  13. length = props.length,
  14. index = fromRight ? length : -1;
  15. while ((fromRight ? index-- : ++index < length)) {
  16. var key = props[index];
  17. if (iteratee(iterable[key], key, iterable) === false) {
  18. break;
  19. }
  20. }
  21. return object;
  22. };
  23. }
  24. export default createBaseFor;