JSFiddle - React, Tailwind, and code Playground
by yasemin CerrahoÄźlu
JavaScript
let arr = [-4, 3, -9, 0, 4, 1];
//arr.sort();
const negatives= [],
positives= [],
zeros= [],
result= [];
let resault="";
for (let i=0; i< arr.length; i++) {
arr[i] < 0 && negatives.push(arr[i])
arr[i] > 0 && positives.push(arr[i])
arr[i] == 0 && zeros.push(arr[i]);
}
array.forEach(function callback(currentValue [, index [, array]]) {
// code for this iteration
}[, thisArg]);
const calc= (a) => resault+=`${(a / arr.length).toFixed(6)}\n`;
calc(positives.length, negatives.length);
//calc(negatives.length);
//calc(zeros.length);
console.log(resault);