From e0f9e919c783042486d59ecd00d3489262b18b60 Mon Sep 17 00:00:00 2001 From: kuangshen04 <2832899707@qq.com> Date: Sat, 7 Oct 2023 23:10:54 +0800 Subject: [PATCH] array.prototype --- game/game.js | 256 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 153 insertions(+), 103 deletions(-) diff --git a/game/game.js b/game/game.js index 4719ba8a9..dbe926e8b 100644 --- a/game/game.js +++ b/game/game.js @@ -8418,159 +8418,209 @@ }); /*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))); + 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))); + 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))); } }); /** * @legacy Use `Array.prototype.includes(searchElement)` instead. */ Object.defineProperty(Array.prototype, "contains", { - configurable:true, - enumerable:false, - writable:true, - value:Array.prototype.includes + configurable: true, + enumerable: false, + writable: true, + value: Array.prototype.includes }); + 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 () { + return Array.from(arguments).every(i=>this.includes(i)); + } + }); + Object.defineProperty(Array.prototype, "add", { - configurable:true, - enumerable:false, - writable:true, - value:function(){ - for(var 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]); + } + return list; } }); Object.defineProperty(Array.prototype, "randomRemove", { - configurable:true, - enumerable:false, - writable:true, - value:function(num){ - if(typeof num=='number'){ - var list=[]; - for(var i=0;ithis.length){ - num=this.length; - } - var arr=this.slice(0); - var list=[]; - for(var i=0;i true)); + 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',{