# 如何实现一个 sampleSize 函数,从数组中随机取 N 个元素
Issue
欢迎在 Gtihub Issue 中回答此问题: Issue 696 (opens new window)
Author
const shuffle = (list) => list.sort((x, y) => Math.random() - 0.5);
const sampleSize = (list, n) => shuffle(list).slice(0, n);
Issue
欢迎在 Gtihub Issue 中回答此问题: Issue 696 (opens new window)
Author
const shuffle = (list) => list.sort((x, y) => Math.random() - 0.5);
const sampleSize = (list, n) => shuffle(list).slice(0, n);