我尝试读取输入并转移到两个数字N和K,并将数字投票数组作为参数传递给函数,并返回数字数组。并在每行上打印数组的每个元素。但是当我打印出每个元素时,第一个整数带有无处字母' D'。这是终端的样子。前两行是输入并使用ctrl + D来确定并获取数组[3,0,-2]。
请帮我弄清楚这封信' D'。谢谢大家。
5 3 1 2 3 1 1 3D 0 -2
process.stdin.resume();
process.stdin.setEncoding("ascii");
let line1 = ""
let line2 = ""
process.stdin.on("data", function(data) {
if (line1 != "" && line2 == "") {
line2 += data
} else if (line1 == "") {
line1 += data
}
})
process.stdin.on("end", function() {
let N = line1.split(' ').map(Number)[0];
let K = line1.split(' ').map(Number)[1];
let votes = line2.split(' ').map(Number);
processData(N, K, votes);
})
function processData(N, K, votes) {
// call upvotesAnalyze function, it will return an array
// like [3, 0, -2]
let results = upvotesAnalyze(votes, N, K);
results.forEach(e => {
// or I have tried
// process.stdout.write(e);
console.log(e);
})
}