I've been stuck for days. Please help! new to javascript
first I mapped the students scores, and got an array of just the number scores. Then I wrote a if/else function to take the student score and convert it to a letter grade. But how can I take this array of letter grade and list out all the students that got each grade? and then write this in es6 into the getStudentsByGrade const??
var studentScores = students.map(function (student) {
return student.score;
})
console.log(studentScores);
function toLetterGrade(studentScores) {
var textG = '';
var result = [];
for (i = 0; i < studentScores.length; i++) {
textG = '';
if (studentScores[i] >= 90) {
textG = "A";
} else if (studentScores[i] >= 80) {
textG = "B";
} else if (studentScores[i] >= 60) {
textG = "C";
} else if (studentScores[i] >= 50) {
textG = "D";
} else if (studentScores[i] >= 32) {
textG = "E";
} else {
textG = "F";
}
result.push(textG);
}
return result;
}
console.log(toLetterGrade(studentScores));
Given a list of students with a name and a score, write a function getStudentsByGrade
that takes in an array of students and a set of grade boundaries and gives you an gives you an object with a list of grades and the names of students for each grade.
the output should be:
{
A: ['Dan'],
C: ['Emily', 'Daisy'],
E: ['Brendan']
}
And must be written inside the following
const getStudentsByGrade = (students, gradeBoundaries) => {
// solution in here
}
Given:
const students = [{name: 'Daisy', score: 65},
{name: 'Dan', score: 99},
{name: 'Emily', score: 77},
{name: 'Brendan', score: 49}];
const gradeBoundaries = {A: 90, B: 80, C: 60, D: 50, E: 32, F: 0};
const getStudentsByGrade = (students, gradeBoundaries) => {
// How do I do this?
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…