(Created page with "'use strict'; function PrimitiveSet() { this.data = {}; this.counter = 0; } PrimitiveSet.prototype.add = function(val) { if (!this.data.hasOwnProperty(val)) { this.data[val] = this.counter; this.counter++; } }; PrimitiveSet.prototype.clear = function() { this.data = {}; this.counter = 0; }; PrimitiveSet.prototype.delete = function( val ) { delete this.data[val]; }; PrimitiveSet.prototype.has = function( val ) { return val in this.data; }; PrimitiveSet.p...") |
m (ChaoticShadow moved page MediaWiki:Gadget-polyfill.js to MediaWiki:Gadget-polyfill-set.js without leaving a redirect) |
||
(No difference)
|
Revision as of 04:40, 21 December 2021
'use strict';
function PrimitiveSet() {
this.data = {};
this.counter = 0;
}
PrimitiveSet.prototype.add = function(val) {
if (!this.data.hasOwnProperty(val)) {
this.data[val] = this.counter;
this.counter++;
}
};
PrimitiveSet.prototype.clear = function() {
this.data = {};
this.counter = 0;
};
PrimitiveSet.prototype.delete = function( val ) {
delete this.data[val];
};
PrimitiveSet.prototype.has = function( val ) {
return val in this.data;
};
PrimitiveSet.prototype.values = function() {
var key_vals = [];
for (var key in this.data) {
key_vals.push( { key: key, value: this.data[key] } );
}
key_vals.sort( function( left, right ) {
return left.value - right.value;
} );
return key_vals.map( function( key_val ) {
return key_val.key;
} );
};
Object.preventExtensions(PrimitiveSet.prototype);