题解 | #元素按照升序或降序进行排序#
输入整型数组和排序标识,对其元素按照升序或降序进行排序
https://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309
const readline = require('readline'); const data: string[] = []; const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.on('line', function (line) { data.push(line); }); rl.on('close', () => { if (data[2] === '0') { console.log(data[1].split(' ').sort((a, b) => Number(a) - Number(b)).join(' ')); } else if (data[2] === '1') { console.log(data[1].split(' ').sort((a, b) => Number(b) - Number(a)).join(' ')); } })