mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
Merge branch 'master' into indev
This commit is contained in:
@@ -3,6 +3,16 @@
|
||||
* @extends {Map}
|
||||
*/
|
||||
class Collection extends Map {
|
||||
set(key, value) {
|
||||
super.set(key, value);
|
||||
this.changed = true;
|
||||
}
|
||||
|
||||
delete(key) {
|
||||
super.delete(key);
|
||||
this.changed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ordered array of the values of this collection.
|
||||
* @returns {Array}
|
||||
@@ -67,8 +77,11 @@ class Collection extends Map {
|
||||
* @returns {*}
|
||||
*/
|
||||
random() {
|
||||
const arr = this.array();
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
if (!this.cachedArray || this.cachedArray.length !== this.size || this.changed) {
|
||||
this.cachedArray = this.array();
|
||||
this.changed = false;
|
||||
}
|
||||
return this.cachedArray[Math.floor(Math.random() * this.cachedArray.length)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,8 +90,11 @@ class Collection extends Map {
|
||||
* @returns {*}
|
||||
*/
|
||||
randomKey() {
|
||||
const arr = this.keyArray();
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
if (!this.cachedKeyArray || this.cachedKeyArray.length !== this.size || this.changed) {
|
||||
this.cachedKeyArray = this.keyArray();
|
||||
this.changed = false;
|
||||
}
|
||||
return this.cachedKeyArray[Math.floor(Math.random() * this.cachedKeyArray.length)];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user