This commit is contained in:
Snowflake 2020-12-14 13:32:13 +05:45 committed by GitHub
parent 96ae0a5398
commit dd2c3c1f8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -28,7 +28,7 @@ export class Collection<K = string, V = any> extends Map<K, V> {
const arr = this.array()
if (typeof amount === 'undefined') return arr[arr.length - 1]
if (amount < 0) return this.first(amount * -1)
if (!amount) return []
if (typeof amount !== 'number' && !amount) return []
return arr.slice(-amount)
}
@ -38,7 +38,7 @@ export class Collection<K = string, V = any> extends Map<K, V> {
random(amount?: number): V | V[] {
let arr = this.array()
if (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)]
if (arr.length === 0 || !amount) return []
if (arr.length === 0 || typeof amount !== 'number' && !amount) return []
arr = arr.slice()
return Array.from({ length: amount }, (): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0])
}