You are viewing a single comment's thread. Return to all comments →
Here is my solution: var positive_count = 0, negative_count = 0; var zero_count = 0; arr = arr.map(function(num){ if(num>0){ positive_count+=1; } else if(num<0){ negative_count+=1; }else{ zero_count +=1; } }); console.log((positive_count/n).toFixed(6)); console.log((negative_count/n).toFixed(6)); console.log((zero_count/n).toFixed(6)); Using the toFixed() method !
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →
Here is my solution: var positive_count = 0, negative_count = 0; var zero_count = 0; arr = arr.map(function(num){ if(num>0){ positive_count+=1; } else if(num<0){ negative_count+=1; }else{ zero_count +=1; } }); console.log((positive_count/n).toFixed(6)); console.log((negative_count/n).toFixed(6)); console.log((zero_count/n).toFixed(6)); Using the toFixed() method !