-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplusMinus.js
More file actions
31 lines (25 loc) · 702 Bytes
/
Copy pathplusMinus.js
File metadata and controls
31 lines (25 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* Complete the 'plusMinus' function below.
*
* The function accepts INTEGER_ARRAY arr as parameter.
*/
let arr = [-4, 3, -9, 0, 4, 1]
function plusMinus(arr) {
// Write your code here
let positiveNumbers = 0;
let negativeNumbers = 0;
let zeroNumbers = 0;
for (let element of arr) {
if (element < 0) {
negativeNumbers++
} else if(element > 0) {
positiveNumbers++
} else {
zeroNumbers++;
}
}
console.log((positiveNumbers / arr.length).toFixed(6));
console.log((negativeNumbers / arr.length).toFixed(6));
console.log((zeroNumbers / arr.length).toFixed(6));
}
console.log(plusMinus(arr));