main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
890 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var aSet = require('../internals/a-set');
|
---|
3 | var SetHelpers = require('../internals/set-helpers');
|
---|
4 | var size = require('../internals/set-size');
|
---|
5 | var getSetRecord = require('../internals/get-set-record');
|
---|
6 | var iterateSet = require('../internals/set-iterate');
|
---|
7 | var iterateSimple = require('../internals/iterate-simple');
|
---|
8 |
|
---|
9 | var Set = SetHelpers.Set;
|
---|
10 | var add = SetHelpers.add;
|
---|
11 | var has = SetHelpers.has;
|
---|
12 |
|
---|
13 | // `Set.prototype.intersection` method
|
---|
14 | // https://github.com/tc39/proposal-set-methods
|
---|
15 | module.exports = function intersection(other) {
|
---|
16 | var O = aSet(this);
|
---|
17 | var otherRec = getSetRecord(other);
|
---|
18 | var result = new Set();
|
---|
19 |
|
---|
20 | if (size(O) > otherRec.size) {
|
---|
21 | iterateSimple(otherRec.getIterator(), function (e) {
|
---|
22 | if (has(O, e)) add(result, e);
|
---|
23 | });
|
---|
24 | } else {
|
---|
25 | iterateSet(O, function (e) {
|
---|
26 | if (otherRec.includes(e)) add(result, e);
|
---|
27 | });
|
---|
28 | }
|
---|
29 |
|
---|
30 | return result;
|
---|
31 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.