Record

개념

  • 자료구조

목차

forEach

  • thisArg 매개변수(this)를 forEach()에 제공했기에, callback은 전달받은 this의 값을 자신의 this 값으로 사용할 수 있습니다.
    • arr.forEach(callback(currentvalue[, index[, array]])[, thisArg])
fruits.forEach((fruit) => console.log(fruit, second), second);

// Q9. compute students' average score
{
  const result = students.reduce((prev, curr) => prev.score + curr.score);
  console.log(result / students.length);
}


// Q10. make a string containing all the scores
// result should be: '45, 80, 90, 66, 88'
{
  const result = students
    .map((student) => student.score)
    .filter((score) => score >= 50)
    .join();
  console.log(result);
}

// Bonus! do Q10 sorted in ascending order
// result should be: '45, 66, 80, 88, 90'
{
  const result = students
    .map((student) => student.score)
    .sort((a, b) => b - a)
    .join();
  console.log(result);
}