题解 | #无重复数组#
无重复数组
https://www.nowcoder.com/practice/d2fa3632268b41df9bc417b74802ad8c
<script>
const _getUniqueNums = (start, end, n) => {
// 补全代码
var min = Math.ceil(start)
var max = Math.floor(end)
var arr = []
for (var i = 0; i < n; i++) {
number = Math.floor(Math.random() * (max - min + 1)) + min//含最大值,含最小值
if (arr.indexOf(number) !== -1) { //判断数组中是否有该数
i--
} else {
arr.push(number)
}
}
return arr
}
console.log(_getUniqueNums(1, 4, 4))
</script>