mirror of
https://github.com/samsonjs/batteries.git
synced 2026-04-27 15:07:42 +00:00
make set compatible with non-strings, still very slow
This commit is contained in:
parent
d2b88f5c54
commit
92912c0678
1 changed files with 8 additions and 3 deletions
11
lib/set.js
11
lib/set.js
|
|
@ -42,7 +42,7 @@ Set.prototype.diff = function(other) {
|
||||||
var d = []
|
var d = []
|
||||||
, x
|
, x
|
||||||
;
|
;
|
||||||
for (x in this.members) if (!(x in other.members)) d.push(x);
|
for (x in this.members) if (!(x in other.members)) d.push(this.members[x]);
|
||||||
return new Set(d);
|
return new Set(d);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -58,9 +58,14 @@ Set.prototype.remove = function(item) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Set.prototype.toArray = function() {
|
Set.prototype.toArray = function() {
|
||||||
return Object.keys(this.members);
|
var ms = this.members;
|
||||||
|
return ownProps(this.members).map(function(k) { return ms[k]; });
|
||||||
};
|
};
|
||||||
|
|
||||||
Set.prototype.union = function(other) {
|
Set.prototype.union = function(other) {
|
||||||
return new Set(ownProps(this.members).concat(ownProps(other.members)));
|
var ms = this.members;
|
||||||
|
, u = ownProps(this.members).map(function(k) { return ms[k]; });
|
||||||
|
ms = other.members;
|
||||||
|
u = u.concat(ownProps(ms).map(function(k) { return ms[k]; }));
|
||||||
|
return new Set(u);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue