calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with places after the decimal.

Given an array of integers, calculate the ratios of its elements that are positivenegative, and zero. Print the decimal value of each fraction on a new line with  places after the decimal.

function plusMinus(arr) {
  let minusNumber = 0
  let plusNumber = 0
  let ZeroNumber = 0
 
  for(let i = 0 ; i<arr.length; i++){
      if(arr[i]<0){
          minusNumber+=1
      }else if (arr[i]>0){
          plusNumber+=1
      }else{
          ZeroNumber+=1
      }
     
  }
 
  let  plus = plusNumber/arr.length
  let zero = ZeroNumber/arr.length
  let minus = (minusNumber/arr.length)

  console.log(plus.toFixed(6));
  console.log(minus.toFixed(6))
  console.log(zero.toFixed(6));

}



Comments

Popular posts from this blog

TimeConversion in 24 hour format

minimum and maximum values that can be calculated

calculate the absolute difference between the sums of its diagonals.