Функция для получения отношения числа положительных, отрицательных и нулевых значений внутри массива по отношению к его длине
I wrote a function that checks what's the ratio of the number of positive, negative and null values inside an array in relation to its length. I'd like receive some feedback on why my code's logic doesn't work.
Что я уже пробовал:
The code I wrote is the following: ``` function plusMinus(arr) { /**first I declare 3 variables to store the positive, negative and null elements inside them*/ let numPositive = []; let numNegative = []; let numZero = []; /**then I write a loop that will check whether the elements of the input array are positive, negative or null, e.g. if the element[i] is positive, then the array numPositive pushes the positive element[i] inside it, and so on for the rest of the numbers and arrays*/ for (let i=0; i<arr.length;i++){ if (arr[i]>0){ numPositive.push(arr[i]>0); }else if (arr[i]<0){ numNegative.push(arr[i]<0); }else{ numZero.push(arr[i]==0) } } /**finally, the ratios are given as a result of the length of the pushed arrays and the length of the original array*/ console.log(numPositive.length/arr.length); console.log(numNegative.length/arr.length); console.log(numZero.length/arr.length); } ```