题解 | #明明的随机数#

明明的随机数

https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    const data = [];
    while ((line = await readline())) {
        //存储数据到数组
        data.push(line);
    }
    //去除个数N
    data.shift();
    //利用Set特性去重,通过sort从小到大排序
    const sortData = [...new Set(data)].sort((a, b) => {
        return a - b;
    });
    //遍历输出结果
    sortData.forEach((el) => {
        console.log(el);
    });
})();

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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