Skip to content

Instantly share code, notes, and snippets.

@ldco2016
Created November 12, 2017 22:26
Show Gist options
  • Save ldco2016/b70501055154930b6b321da8fcaa4f0f to your computer and use it in GitHub Desktop.
Save ldco2016/b70501055154930b6b321da8fcaa4f0f to your computer and use it in GitHub Desktop.
function main() {
var n = parseInt(readLine());
arr = readLine().split(' ');
arr = arr.map(Number);
let positive = negative = zero = 0;
for (i =0; i < n; i++){
let current = arr[i];
if (current > 0) {
positive += 1;
} else if (current < 0) {
negative += 1;
} else {
zero += 1;
}
}
console.log((positive / n).toFixed(6));
console.log((negative / n).toFixed(6));
console.log((zero / n).toFixed(6));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment