• + 0 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)
    }