Plus Minus

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