You are viewing a single comment's thread. Return to all 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));
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 →
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 });