题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
while (line = readline()) { let arr = readline().split(" "); let fuNum = arr.filter((item) => parseInt(item) < 0).length; //负数的个数 let zArr = arr.filter((item) => item > 0);//正数的数组 // 正数长度为0,即没有正数 if (zArr.length == 0) { console.log(fuNum + " " + "0.0"); break; } let sum = zArr.reduce((preV, curV) => parseInt(preV) + parseInt(curV)); //正数的总和 let average = (sum / zArr.length).toFixed(1); //正数的平均值 console.log(fuNum + " " + average); }