JSFiddle - React, Tailwind, and code Playground

by the_archer

JavaScript

//function to calculate average, pa try comprend, mne gagne sa depui net :-) 
Array.prototype.average = function() {
  var sum = 0,
    j = 0;
  for (var i = 0; i < this.length, isFinite(this[i]); i++) {
    sum += parseFloat(this[i]);
    ++j;
  }
  return j ? sum / j : 0;
};

//Code Starts From Here

var dataSet = [9, 10, 12, 34, 54]; //To range of excel values in the column
var F6 = 2; //value of cell F6, set to zero to test max function
var G6 = 1; //value of cell G6, set to zero to test max function

document.write(getResult(F6, G6, dataSet)); //Output Value

//The formula, in excel
function getResult(F6, G6, dataSet) {
  if (F6 == 0 || G6 == 0) {
    return Math.max.apply(Math, dataSet);
  } else {
    return dataSet.average();
  }
}