You are viewing a single comment's thread. Return to all comments →
Javascript solution:
function plusMinus(arr) { if (arr.length > 100 || Math.min(...arr) < -100 || Math.max(...arr) > 100) return let positiveCount = 0 let negativeCount= 0 let zeroCount =0 arr.forEach(int => { if (Math.sign(int) === 1) ++positiveCount; else if (Math.sign(int) === -1 ) ++negativeCount; else if (Math.sign(int) === 0) ++zeroCount; }) console.log((positiveCount / arr.length).toFixed(6)) console.log((negativeCount / arr.length).toFixed(6)) console.log((zeroCount / arr.length).toFixed(6)) }
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 →
Javascript solution: