plusMinus

    0

    0

    The code initializes variables minus, plus, zero, and result. It then loops through the arr object, calling the plusMinus() function on each item. The plusMinus() function adds the value of minus to the value of plus for each item in arr. The function then logs the results to the console.

    function plusMinus(arr) {
      let minus = 0,
        plus = 0,
        zero = 0,
        result = [],
        length = arr.length;
    
      arr.forEach((item) => {
        item === 0 ? zero++ : item < 0 ? minus++ : plus++;
      });
    
      console.log((plus / length).toPrecision(3));
      console.log((minus / length).toPrecision(3));
      console.log((zero / length).toPrecision(3));
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.