I'm a beginner and looking to create a function that can filter out negative, positive, and zero values in an array. Although I have managed to achieve this using a for loop with hardcoded numbers, I am struggling to convert it into a reusable function. Can someone please assist me with this?
var arr=[1,3,5,-9,-3,0];
var new_arr = [];
var new_arr2 = [];
var new_arr3=[];
for(i =0; i < arr.length; i++){
if(arr[i]>0){
new_arr.push(arr[i]);
}
else if(arr[i]<0){
new_arr2.push(arr[i]);
}
else if(arr[i]===0){
new_arr3.push(arr[i]);
}
}
console.log(new_arr3.length/arr.length);
console.log(new_arr2.length/arr.length);
console.log(new_arr.length/arr.length);