intersection.js 446 B

12345678910111213141516171819
  1. import {InternSet} from "internmap";
  2. export default function intersection(values, ...others) {
  3. values = new InternSet(values);
  4. others = others.map(set);
  5. out: for (const value of values) {
  6. for (const other of others) {
  7. if (!other.has(value)) {
  8. values.delete(value);
  9. continue out;
  10. }
  11. }
  12. }
  13. return values;
  14. }
  15. function set(values) {
  16. return values instanceof InternSet ? values : new InternSet(values);
  17. }