题解 | #明明的随机数#

明明的随机数

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);
    })
}()

全部评论

相关推荐

01-14 12:34
门头沟学院 C++
牛马人的牛马人生:太暖心了啊 配环境是真烦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务