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!
function betterThanAverage(classPoints, yourPoints) {
classPoints.push(yourPoints);
return (classPoints.reduce((sum, cur) => sum + cur))
/ classPoints.length < yourPoints ? true : false
}
나는 .push
로 배열에 넣어주고 작업했는데, .reudce
를 할 때 초깃값으로 내 점수를 넣고, 나누기에 배열의 길이 + 1 하는 방법도 있다.
function betterThanAverage(classPoints, yourPoints) {
return yourPoints > classPoints.reduce(function(sum, x){return sum + x},yourPoints)/(classPoints.length+1)
}