From 27ddea07309935292a5b64d7e189afc64d1cc147 Mon Sep 17 00:00:00 2001 From: kuangshen04 <2832899707@qq.com> Date: Sun, 8 Oct 2023 15:19:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E7=A9=BA=E6=A0=BC=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96addArray,removeArray=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 269 ++++++++++++++++++++++++++------------------------- 1 file changed, 135 insertions(+), 134 deletions(-) diff --git a/game/game.js b/game/game.js index dbe926e8b..9bc3a9ab5 100644 --- a/game/game.js +++ b/game/game.js @@ -8417,206 +8417,207 @@ } }); /*Map prototype end*/ - Object.defineProperty(Array.prototype, "filterInD", { - configurable: true, - enumerable: false, - writable: true, - value: function (pos) { - if (typeof pos != 'string') pos = 'o'; - return this.filter(card => pos.includes(get.position(card, true))); + Object.defineProperty(Array.prototype,"filterInD",{ + configurable:true, + enumerable:false, + writable:true, + value:function(pos){ + if(typeof pos!='string') pos='o'; + return this.filter(card=>pos.includes(get.position(card,true))); } }); - Object.defineProperty(Array.prototype, "someInD", { - configurable: true, - enumerable: false, - writable: true, - value: function (pos) { - if (typeof pos != 'string') pos = 'o'; - return this.some(card => pos.includes(get.position(card, true))); + Object.defineProperty(Array.prototype,"someInD",{ + configurable:true, + enumerable:false, + writable:true, + value:function(pos){ + if(typeof pos!='string') pos='o'; + 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))); + 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", { - configurable: true, - enumerable: false, - writable: true, - value: Array.prototype.includes + Object.defineProperty(Array.prototype,"contains",{ + configurable:true, + enumerable:false, + writable:true, + value:Array.prototype.includes }); - Object.defineProperty(Array.prototype, "containsSome", { - configurable: true, - enumerable: false, - writable: true, - value: function () { + Object.defineProperty(Array.prototype,"containsSome",{ + configurable:true, + enumerable:false, + writable:true, + value:function(){ return Array.from(arguments).some(i=>this.includes(i)); } }); - Object.defineProperty(Array.prototype, "containsAll", { - configurable: true, - enumerable: false, - writable: true, - value: function () { + Object.defineProperty(Array.prototype,"containsAll",{ + configurable:true, + enumerable:false, + writable:true, + value:function(){ return Array.from(arguments).every(i=>this.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; + 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 () { - return Array.prototype.add.apply(this,Array.from(arguments).flat()); + Object.defineProperty(Array.prototype,"addArray",{ + configurable:true, + enumerable:false, + writable:true, + value:function(){ + for(const i of arguments) this.add(...i); + return this; } }); - Object.defineProperty(Array.prototype, "remove", { - configurable: true, - enumerable: false, - writable: true, - value: function () { + 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); + 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 () { - return Array.prototype.remove.apply(this,Array.from(arguments).flat()); + Object.defineProperty(Array.prototype,"removeArray",{ + configurable:true, + enumerable:false, + writable:true, + value:function(){ + for(const i of arguments) this.add(...i); } }); - Object.defineProperty(Array.prototype, "unique", { - configurable: true, - enumerable: false, - writable: true, - value: function () { - let uniqueArray = this.toUniqued(); - this.length = uniqueArray.length; - for (let i = 0; i < uniqueArray.length; i++) this[i] = uniqueArray[i]; + 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;i this.length) num = this.length; - let arr = this.slice(0); - let list = []; - for (let i = 0; i < num; i++) { - list.push(arr.splice(Math.floor(Math.random() * arr.length), 1)[0]); + Object.defineProperty(Array.prototype,"randomGets",{ + configurable:true, + enumerable:false, + writable:true, + value:function(num){ + if(num>this.length) num=this.length; + let arr=this.slice(0); + let list=[]; + for(let i=0;i true)); - if (sortBy && typeof sortBy == 'function') list.sort((a, b) => sortBy(a) - sortBy(b)); + Object.defineProperty(Array.prototype,"maxBy",{ + 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[list.length - 1]; + 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)); + 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]; }