题解 | #无重复数组#
无重复数组
https://www.nowcoder.com/practice/d2fa3632268b41df9bc417b74802ad8c
{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n\n<head>\n <meta charset=\"UTF-8\">\n</head>\n\n<body>\n\n <script>\n const _getUniqueNums = (start, end, n) => {\n let arr = []\n let ran = 0\n // 补全代码\n // debugger\n for (let i = 0; arr.length !== n; i++) {\n ran = Math.floor(Math.random() * (end - start) + start + 1)\n // debugger\n for (let j = 0; arr.length !== n; j++) {\n if (ran === arr[j]) {\n break\n }\n if (j === arr.length) {\n arr.push(ran)\n break\n }\n }\n }\n console.log(arr);\n return arr\n }\n _getUniqueNums(10, 16, 5)\n </script>\n</body>\n\n</html>","libs":[]}