Created
February 21, 2023 10:11
-
-
Save Nasah-Kuma/9e7f50a4d33c3ad9b4b0cf3d1824ba17 to your computer and use it in GitHub Desktop.
Solution to HackerRank's PlusMinus challenge: https://www.hackerrank.com/challenges/plus-minus/problem?isFullScreen=true
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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