Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement