diff --git a/game/game.js b/game/game.js index e8c11bdb3..388ae0769 100644 --- a/game/game.js +++ b/game/game.js @@ -8417,7 +8417,7 @@ } }); /*Map prototype end*/ - Object.defineProperty(Array.prototype, "filterInD", { + Object.defineProperty(Array.prototype,"filterInD",{ configurable:true, enumerable:false, writable:true, @@ -8426,7 +8426,7 @@ return this.filter(card=>pos.includes(get.position(card,true))); } }); - Object.defineProperty(Array.prototype, "someInD", { + Object.defineProperty(Array.prototype,"someInD",{ configurable:true, enumerable:false, writable:true, @@ -8435,132 +8435,159 @@ return this.some(card=>pos.includes(get.position(card,true))); } }); + Object.defineProperty(Array.prototype,"everyInD",{ + configurable:true, + enumerable:false, + writable:true, + value:function(pos){ + if(typeof pos!='string') pos='o'; + return this.every(card=>pos.includes(get.position(card,true))); + } + }); /** - * @legacy Use `Array.prototype.includes(searchElement)` instead. + *@legacy Use `Array.prototype.includes(searchElement)` instead. */ - Object.defineProperty(Array.prototype, "contains", { + Object.defineProperty(Array.prototype,"contains",{ configurable:true, enumerable:false, writable:true, value:Array.prototype.includes }); - Object.defineProperty(Array.prototype, "add", { + Object.defineProperty(Array.prototype,"containsSome",{ configurable:true, enumerable:false, writable:true, value:function(){ - for(var i=0;ithis.includes(i)); } }); - Object.defineProperty(Array.prototype, "addArray", { - configurable:true, - enumerable:false, - writable:true, - value:function(arr){ - for(var i=0;ithis.includes(i)); + } + }); + + Object.defineProperty(Array.prototype,"add",{ + configurable:true, + enumerable:false, + writable:true, + value:function(){ + for(const arg of arguments){ + if(this.contains(arg)) continue; + this.push(arg); + } + return this; + } + }); + Object.defineProperty(Array.prototype,"addArray",{ + configurable:true, + enumerable:false, + writable:true, + value:function(){ + for(const i of Array.from(arguments)) this.add(...i); + return this; + } + }); + Object.defineProperty(Array.prototype,"remove",{ + configurable:true, + enumerable:false, + writable:true, + value:function(){ + for(const item of arguments){ + const pos=this.indexOf(item); + if(pos==-1) continue; + this.splice(pos,1); + } + return this; + } + }); + Object.defineProperty(Array.prototype,"removeArray",{ + configurable:true, + enumerable:false, + writable:true, + value:function(){ + for(const i of Array.from(arguments)) this.remove(...i); + return this; + } + }); + Object.defineProperty(Array.prototype,"unique",{ + configurable:true, + enumerable:false, + writable:true, + value:function(){ + let uniqueArray=[...new Set(this)]; + this.length=uniqueArray.length; + for(let i=0;ithis.length){ - num=this.length; - } - var arr=this.slice(0); - var list=[]; - for(var i=0;ithis.length) num=this.length; + let arr=this.slice(0); + let list=[]; + for(let i=0;itrue)); + if(sortBy&&typeof sortBy=='function') list.sort((a,b)=>sortBy(a)-sortBy(b)); + else list.sort(); + return list[list.length-1]; + } + }); + Object.defineProperty(Array.prototype,"minBy",{ + configurable:true, + enumerable:false, + writable:true, + value:function(sortBy,filter){ + let list=this.filter(filter||(()=>true)); + if(sortBy&&typeof sortBy=='function') list.sort((a,b)=>sortBy(a)-sortBy(b)); + else list.sort(); + return list[0]; + } + }); //!!!WARNING!!! //Will be deprecated in next verision Object.defineProperty(Object.prototype,'hasNature',{