every.js 507 B

1234567891011121314151617181920
  1. "use strict";
  2. // This is an `every` implementation that works for all iterables
  3. module.exports = function every(obj, fn) {
  4. var pass = true;
  5. try {
  6. /* eslint-disable-next-line local-rules/no-prototype-methods */
  7. obj.forEach(function() {
  8. if (!fn.apply(this, arguments)) {
  9. // Throwing an error is the only way to break `forEach`
  10. throw new Error();
  11. }
  12. });
  13. } catch (e) {
  14. pass = false;
  15. }
  16. return pass;
  17. };