Skip to content

Instantly share code, notes, and snippets.

@Nasah-Kuma
Created February 21, 2023 10:11
Show Gist options
  • Save Nasah-Kuma/9e7f50a4d33c3ad9b4b0cf3d1824ba17 to your computer and use it in GitHub Desktop.
Save Nasah-Kuma/9e7f50a4d33c3ad9b4b0cf3d1824ba17 to your computer and use it in GitHub Desktop.
function plusMinus(arr) {
// Write your code here
let plusCount = 0;
let minusCount = 0;
let zeroCount = 0;
const n = arr.length;
for (const i of arr) {
if(i < 0) minusCount++;
if(i > 0) plusCount++;
if(i === 0) zeroCount++;
}
console.log(`${(plusCount++/n).toPrecision(6)}\n${(minusCount++/n).toPrecision(6)}\n${(zeroCount++/n).toPrecision(6)}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment