everySet.js 684 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. *
  8. * @typechecks
  9. */
  10. 'use strict';
  11. /**
  12. * The everySet() method tests whether all elements in the given Set pass the
  13. * test implemented by the provided function.
  14. */
  15. function everySet(set, callback, context) {
  16. var iterator = set.entries();
  17. var current = iterator.next();
  18. while (!current.done) {
  19. var entry = current.value;
  20. if (!callback.call(context, entry[1], entry[0], set)) {
  21. return false;
  22. }
  23. current = iterator.next();
  24. }
  25. return true;
  26. }
  27. module.exports = everySet;