showing results for - "plus minus hackerrank solution in javascript"
Valentino
07 Feb 2020
1function plusMinus(arr) {
2    let positive = arr.filter(number => number > 0).length / arr.length;
3    let negative = arr.filter(number => number < 0).length / arr.length;;
4    let zeronums = arr.filter(number => number == 0).length / arr.length;;
5    return console.log(positive.toFixed(6) + '\n' + negative.toFixed(6) + '\n' + zeronums.toFixed(6))
6}
7
Greta
22 Jul 2020
1const plusMinus = (arr) => {
2  let posSum = 0;
3  let negSum = 0
4  let zeroes = 0
5  arr.forEach(el => {
6    if(el === 0){
7      zeroes++
8
9    } else if (el >= 1) {
10      posSum++
11
12    } else if (el < 0) {
13      negSum++
14      
15    }
16  })
17    negSum /= arr.length
18    posSum /= arr.length
19    zeroes /= arr.length
20    console.log(posSum)
21    console.log(negSum)
22    console.log(zeroes)
23}
24plusMinus([1,1,0,-1,-1])