/* eslint-disable arrow-body-style */
/* eslint-disable no-unused-expressions */
export const roundHalf = (num) => {
  return Math.round(num * 2) / 2;
};

export const getRating = (rating) => {
  // check if rating is an array or a number
  let rate = 0;
  if (Array.isArray(rating)) {
    const sum = rating.reduce((a, b) => parseInt(a) + parseInt(b));
    const avg = sum / rating.length;
    rate = roundHalf(avg);
  } else {
    rate = roundHalf(rating);
  }
  return rate;
};
