Skip to content

Instantly share code, notes, and snippets.

Array.prototype.sample = function(n) {
return Array.from(this).sort(_ => Math.random() - 0.5).splice(0, n > this.length ? this.length : n||1)
}
let hoge = [1,2,3,4,5];
console.log(hoge.sample(3));
console.log(hoge.sample(6));