Revision of Plus and Minus

Run Settings
LanguageJavaScript
Language Version
Run Command
//also use arr.reverse function processData(input) { let arr = input.split("\n")[1].split(" ").map(Number) let n = input.split("\n")[0] let neg = 0 , pos = 0 ,zero = 0; arr.forEach(num => { switch ((Math.sign(num)) ){ case 1: pos++ break; case -1: neg++ break; default: zero++ break; } }); console.log(pos/n); console.log(neg/n); console.log(zero/n); } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });
Editor Settings
Theme
Key bindings
Full width
Lines