Grading Students | HackerRank
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| function gradingStudents(grades: number[]): number[] { 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方法遍历数组,为其每项执行回调函数,返回新数组