2020-10-04 04:10:08 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
2020-10-06 01:32:33 +03:00
|
|
|
**********************************************/ /* c8 ignore next 2 */
|
2020-10-04 04:10:08 +03:00
|
|
|
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
|
|
|
|
(function(require){ var module={} // make module AMD/node compatible...
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
2020-10-04 04:40:16 +03:00
|
|
|
// Set set operation shorthands...
|
2020-11-21 03:37:26 +03:00
|
|
|
Set.prototype.unite = function(other=[]){
|
2020-10-04 04:40:16 +03:00
|
|
|
return new Set([...this, ...other]) }
|
|
|
|
|
Set.prototype.intersect = function(other){
|
2020-10-09 03:24:25 +03:00
|
|
|
var test = other.has ?
|
|
|
|
|
'has'
|
|
|
|
|
: 'includes'
|
2020-10-04 04:40:16 +03:00
|
|
|
return new Set([...this]
|
2020-10-09 03:24:25 +03:00
|
|
|
.filter(function(e){
|
|
|
|
|
return other[test](e) })) }
|
2020-11-21 03:37:26 +03:00
|
|
|
Set.prototype.subtract = function(other=[]){
|
2020-10-04 04:40:16 +03:00
|
|
|
other = new Set(other)
|
|
|
|
|
return new Set([...this]
|
2020-10-09 03:24:25 +03:00
|
|
|
.filter(function(e){
|
|
|
|
|
return !other.has(e) })) }
|
2020-10-04 04:40:16 +03:00
|
|
|
|
2020-10-04 04:10:08 +03:00
|
|
|
|
2020-11-21 03:37:26 +03:00
|
|
|
Map.prototype.sort = function(keys=[]){
|
2020-10-07 16:46:59 +03:00
|
|
|
keys = (typeof(keys) == 'function'
|
|
|
|
|
|| keys === undefined) ?
|
|
|
|
|
[...this].sort(keys)
|
|
|
|
|
: keys
|
|
|
|
|
var del = Set.prototype.delete.bind(this)
|
|
|
|
|
var add = Set.prototype.add.bind(this)
|
|
|
|
|
new Set([...keys, ...this])
|
|
|
|
|
.forEach(function(e){
|
|
|
|
|
if(this.has(e)){
|
|
|
|
|
del(e)
|
|
|
|
|
add(e) } }.bind(this))
|
|
|
|
|
return this }
|
|
|
|
|
|
|
|
|
|
|
2020-10-04 04:10:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
* vim:set ts=4 sw=4 : */ return module })
|