We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
题目来源
这道题目将考点拆分成4点,要求用递归算法实现,限制15行代码以内,限制时间10分钟
Math.floor(Math.random() * (max - min + 1) + min)
arr[i]
i++
let arr = new Array(5) let printArr = (arr, i = 0) => { let rand = Math.floor(Math.random() * 31 + 2) if (i < arr.length) { if (!arr.includes(rand)) { arr[i++] = rand } printArr(arr, i) } return arr }
执行结果:
printArr(arr) // 调用 // 输出,每次执行输出结果都不一样 [27, 10, 26, 16, 2]
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目来源
题目
这道题目将考点拆分成4点,要求用递归算法实现,限制15行代码以内,限制时间10分钟
分析
获取min ~ max 范围内的随机数
思路
arr[i]
赋值生成的随机数,直到遍历完数组才返回arr的值arr[i]
赋值时,如果数组中不存在生成的随机数,则给其赋值,并i++
,否则循环调用该函数答案
执行结果:
The text was updated successfully, but these errors were encountered: