跳转到内容

Grading Students

发布于:

Grading Students | HackerRank

function gradingStudents(grades: number[]): number[] {
  // Write your code here
  return grades.map(grades => {
    if (grades < 38) {
      return grades;
    }
    const currentGrades: number = grades;
    const nextFive = Math.ceil(grades / 5) * 5;
    if (nextFive - currentGrades < 3) {
      return nextFive;
    }
    return currentGrades;
  });
}

map方法遍历数组,为其每项执行回调函数,返回新数组