return Math.floor(Math.random() * (max - min)) + min;
}
-// Inspired by https://github.com/jashkenas/underscore/blob/master/underscore.js
+// Inspired by https://github.com/jashkenas/underscore
export function sample(arr, n) {
n = n || 1;
let cpArr = arr.map(e => e);
for (let index = 0; index < n; index++) {
const rand = randInt(index, arr.length);
- const temp = cpArr[index];
- cpArr[index] = cpArr[rand];
- cpArr[rand] = temp;
+ [ cpArr[index], cpArr[rand] ] = [ cpArr[rand], cpArr[index] ];
}
return cpArr.slice(0, n);
}