输入整型数组和排序标识,对其元素按照升序或降序进行排序

输入整型数组和排序标识,对其元素按照升序或降序进行排序

https://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309

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

void async function () {
    const len = await readline();
    const list = (await readline()).split(" ");
    const sortType = await readline();

    const arr = list.slice(0, len);
    const sortFunc = Number(sortType) > 0 ? ((a, b) => b-a) : ((a, b) => a-b);
    arr.sort(sortFunc);

    console.log(arr.join(" "));
}()

全部评论

相关推荐

牛马人的牛马人生:一开始看成了网吧
点赞 评论 收藏
分享
牛客66512506...:那个百度acg是不是个小哥啊,老是问些底层问题狠狠为难,然后kpi
哪些公司在招寒假实习?
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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