every.js 543 B

123456789101112131415161718
  1. define(['./_cb', './_isArrayLike', './keys'], function (_cb, _isArrayLike, keys) {
  2. // Determine whether all of the elements pass a truth test.
  3. function every(obj, predicate, context) {
  4. predicate = _cb(predicate, context);
  5. var _keys = !_isArrayLike(obj) && keys(obj),
  6. length = (_keys || obj).length;
  7. for (var index = 0; index < length; index++) {
  8. var currentKey = _keys ? _keys[index] : index;
  9. if (!predicate(obj[currentKey], currentKey, obj)) return false;
  10. }
  11. return true;
  12. }
  13. return every;
  14. });