Created
June 21, 2021 05:36
-
-
Save yeyuguo/9572744108f05d500204e44155eb0ae7 to your computer and use it in GitHub Desktop.
创建随时数组
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createRandom(start, end) { | |
const range = end - start | |
return start + Math.round(range * Math.random()) | |
} | |
function createList(max=100) { | |
const getInt = ()=> createRandom(1, max) | |
const result = [] | |
let count = 0 | |
while(count < max) { | |
const num = getInt() | |
let index = num === 0 ? 0 : num -1 | |
if(result[index] === undefined) { | |
result[index] = num | |
count++ | |
} | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment