No Description

each.js 741B

12345678910111213141516171819202122232425
  1. var _optimizeCb = require('./_optimizeCb.js');
  2. var _isArrayLike = require('./_isArrayLike.js');
  3. var keys = require('./keys.js');
  4. // The cornerstone for collection functions, an `each`
  5. // implementation, aka `forEach`.
  6. // Handles raw objects in addition to array-likes. Treats all
  7. // sparse array-likes as if they were dense.
  8. function each(obj, iteratee, context) {
  9. iteratee = _optimizeCb(iteratee, context);
  10. var i, length;
  11. if (_isArrayLike(obj)) {
  12. for (i = 0, length = obj.length; i < length; i++) {
  13. iteratee(obj[i], i, obj);
  14. }
  15. } else {
  16. var _keys = keys(obj);
  17. for (i = 0, length = _keys.length; i < length; i++) {
  18. iteratee(obj[_keys[i]], _keys[i], obj);
  19. }
  20. }
  21. return obj;
  22. }
  23. module.exports = each;