JSFiddle - React, Tailwind, and code Playground

JavaScript

const avr = (coll) => {
  if (coll.length === 0) {
    return null;
  } 
  let res = 0;
 
  for (const val of coll) {
    res += val;
  }
res = res/coll.length;
console.log(res);
return res;
}

console.log(avr([]))