题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
// const randomNums = (n)=>{
// if(n <1 || n > 1000 || parseInt(n) != n) {
// console.log('请输入1-1000之间的整数');
// return;
// }
// const numArr = [];
// for(let i = 0; i < n; i++){
// numArr.push(parseInt(Math.random()*500 + 1));
// }
// const numArrNoRepeat = numArr.reduce((prev,next)=>{
// if(prev.indexOf(next) === -1){
// prev.push(next);
// return prev;
// }
// },[]);
// console.log(numArrNoRepeat);
// numArrNoRepeat.sort((a,b)=>a-b);
// console.log(...numArrNoRepeat);
// }
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
// randomNums(await readline());
const numArr = [];
while(line = await readline()){
numArr.push(Number(line));
}
numArr.shift();
const numArrNoRepeat = numArr.reduce((prev,next)=>{
if(prev.indexOf(next) === -1){
prev.push(next);
}
return prev;
},[]);
numArrNoRepeat.sort((a,b)=>a-b);
numArrNoRepeat.forEach(item=>{
console.log(item);
})
}()
