every.js 658 B

123456789101112131415161718192021222324252627
  1. var makeIterator = require('../function/makeIterator_');
  2. /**
  3. * Array every
  4. */
  5. function every(arr, callback, thisObj) {
  6. callback = makeIterator(callback, thisObj);
  7. var result = true;
  8. if (arr == null) {
  9. return result;
  10. }
  11. var i = -1, len = arr.length;
  12. while (++i < len) {
  13. // we iterate over sparse items since there is no way to make it
  14. // work properly on IE 7-8. see #64
  15. if (!callback(arr[i], i, arr) ) {
  16. result = false;
  17. break;
  18. }
  19. }
  20. return result;
  21. }
  22. module.exports = every;