How good are you really?

Lee·2022년 8월 7일

Algorithm

목록 보기
66/92
post-thumbnail

❓ How good are you really?

Q. There was a test in your class and you passed it. Congratulations!
But you're an ambitious person. You want to know if you're better than the average student in your class.

You receive an array with your peers' test scores. Now calculate the average and compare your score!

Return True if you're better, else False!

Note:
Your points are not included in the array of your class's points. For calculating the average point you may add your point to the given array!

✔ Solution

//#my solution
function betterThanAverage(classPoints, yourPoints) {
  // Your code here
  let c = classPoints.reduce((a, b) => a + b);
  let avg = c / classPoints.length;
  if (avg <= yourPoints) {
    return true;
  } else {
    return false;
  }
}

//#other solution
function betterThanAverage(classPoints, yourPoints) {
  return yourPoints > classPoints.reduce((a, b) => a + b) / classPoints.length;
}
profile
Lee

0개의 댓글