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
用递归算法实现,数组长度为5且元素的随机数在2-32间不重复的值
可以拆解为四小项:
The text was updated successfully, but these errors were encountered:
function getNum() { return Math.floor(Math.random() * 32 + 1); } function inset(cur, arr = []) { if (arr.length > 4) return arr; if (!arr.includes(cur)) { arr.push(cur); } return inset(getNum(), arr); } var res = inset(getNum()); console.log(res);
Sorry, something went wrong.
function getRandom() { return Math.floor(Math.random() * 30 + 2); } let arryLen = 5; function getArray(value, arr = []) { if (arr.length >= arryLen) return arr; if (!arr.includes(value)) { arr.push(value); } return getArray(getRandom(), arr); } const arrayVal = getArray(getRandom()); //console.log(arrayVal);
function creatArray(arr = []) { if (arr.length > 4) return arr; var num = Math.floor(Math.random() * 30 + 2); if (!arr.includes(num)) { arr.push(num); } return creatArray(arr); } var reslut = creatArray(); console.log(reslut);
No branches or pull requests
可以拆解为四小项:
The text was updated successfully, but these errors were encountered: