Plus & Minus

Run Settings
LanguageJavaScript
Language Version
Run Command
function plusMinus(arr) { var Ps =0 ; var Ns =0 ; var Os =0 ; var l = arr.length ; for(let i=0;i<l;i++){ var s = Math.sign(arr[i]); if(s==1){ Ps++; } if(s==-1){ Ns++ } if(s==0){ Os++ ; } } var array =[(Ps/l).toFixed(6) ,(Ns/l).toFixed(6),(Os/l).toFixed(6)]; return array.join("/n") + "/n" } /** * * Given an array of integers, calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with places after the decimal. Note: This challenge introduces precision problems. The test cases are scaled to six decimal places, though answers with absolute error of up to are acceptable. Example There are elements, two positive, two negative and one zero. Their ratios are , and . Results are printed as:*/
Editor Settings
Theme
Key bindings
Full width
Lines