题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { line = await readline(); // Write your code here let kvArr = new Map(); let numArr = []; while(line = await readline()){ numArr = line.split(' ').filter(item => item !== '').map(Number); if(kvArr.get(numArr[0])){ kvArr.set(numArr[0], kvArr.get(numArr[0])+numArr[1]); }else { kvArr.set(numArr[0],numArr[1]); } } // 按照键值对的key进行排序 kvArr = new Map([...kvArr].sort((a,b)=>a[0]-b[0])) kvArr.forEach((value, key)=>{ console.log(key+' ' +value); }) }()