Plus Minus

  • + 0 comments

    const { positives, negatives, zeros } = arr.reduce((acc, x) => { if (x > 0) acc.positives += 1; else if (x < 0) acc.negatives += 1; else acc.zeros += 1; return acc; }, { positives: 0, negatives: 0, zeros: 0 });

    console.log((positives / length).toFixed(6));
    console.log((negatives / length).toFixed(6));
    console.log((zeros / length).toFixed(6));