You are viewing a single comment's thread. Return to all comments →
JavaScript solution
function plusMinus(arr) { const long = arr.length let totalPositives = 0 let totalNegatives = 0 let totalZero = 0 arr.forEach(e => { if (e > 0) totalPositives++ if (e < 0) totalNegatives++ if (e === 0) totalZero++ }) const calculateRatio = (total, n) => console.log((total / n).toFixed(6)) calculateRatio(totalPositives, long) calculateRatio(totalNegatives, long) calculateRatio(totalZero, long) }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Plus Minus
You are viewing a single comment's thread. Return to all comments →
JavaScript solution