problema plusminus javascript hackerrank code example
Example 1: plus minus hackerrank solution in javascript
function plusMinus(arr) {
let positive = arr.filter(number => number > 0).length / arr.length;
let negative = arr.filter(number => number < 0).length / arr.length;;
let zeronums = arr.filter(number => number == 0).length / arr.length;;
return console.log(positive.toFixed(6) + '\n' + negative.toFixed(6) + '\n' + zeronums.toFixed(6))
}
Example 2: plus minus js
function plusMinus(arr) { let positives = 0, negatives = 0, zeros = 0; const len = arr.length || 0; if (len > 0 && len <= 100) { arr.map((elem, key) => { if (elem > 0) { positives++; } else if (elem < 0) { negatives++; } else { zeros++; } return elem; }); } console.log((positives / len) || 0); console.log((negatives / len) || 0); console.log((zeros / len) || 0); }