How good are you really?

Lee·2022년 6월 12일
0

Algorithm

목록 보기
13/92
post-thumbnail

❓ Returning Strings

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

function betterThanAverage(classPoints, yourPoints) {
  // Your code here
  const sumNum = classPoints.reduce((add, sum) => {
    return add + sum;
  }, 0);
  console.log(sumNum);
  const avg = sumNum / classPoints.length;
  console.log(avg);

  if (yourPoints > avg) {
    return true;
  } else {
    return false;
  }
}

Check

reduce( )
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce

profile
Lee

0개의 댓글