Open ForeveHG opened 3 years ago
Math.random() * 30 + 2
function buildNum(len, arr=[]) {
if(arr.length < len) {
const num = parseInt(Math.random() * 30 + 2);
if(arr.indexOf(num) == -1 ) arr.push(num)
buildNum(len, arr)
}
return arr
}
buildNum(5); //[3, 12, 18, 7, 20]
题目来源:https://github.com/haizlin/fe-interview/issues/3