someSet.js 681 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 someSet() method tests whether some elements in the given Set pass the
  13. * test implemented by the provided function.
  14. */
  15. function someSet(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 true;
  22. }
  23. current = iterator.next();
  24. }
  25. return false;
  26. }
  27. module.exports = someSet;