const bills = [22, 295, 176, 440, 37, 105, 10, 1100, 86, 52];

const calcTip = bill => {
  return bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2;
};

const calcAvg = arr => {
  let sum = 0;
  let arrayLength = arr.length;
  for (let i = 0; i < arr.length; i++) {
    sum += arr[i];
  }
  return sum / arrayLength;
};

const tips = [];
const totals = [];
for (let i = 0; i < bills.length; i++) {
  tips[i] = calcTip(bills[i]);
  totals[i] = tips[i] + bills[i];
}

console.log(`Bills: ${bills}`);
console.log(`Tips: ${tips}`);
console.log(`Totals: ${totals}`);
console.log(`Average: ${calcAvg(bills)}`);

console.log(calcAvg([1, 2, 3, 4, 5, 6, 7, 8, 9]));
