1
1
Fork 0
exercism/jq/grade-stats/grade-stats.jq
Christina Sørensen e20eb8b4c4
feat: grade-stat
2024-12-06 16:16:13 +01:00

25 lines
572 B
Text

# Given a numeric score between 0 and 100, output a letter grade
# - "A" is 90% - 100%
# - "B" is 80% - 89%
# - "C" is 70% - 79%
# - "D" is 60% - 69%
# - "F" is 0% - 59%
def letter_grade:
if . < 60 then "F"
elif . < 70 then "D"
elif . < 80 then "C"
elif . < 90 then "B"
else "A"
end;
# Given an object that maps a student's name to their grade,
# generate an object that maps the letter grade to the number of
# students with that grade
def count_letter_grades:
reduce .[] as $s (
{A: 0, B: 0, C: 0, D: 0, F: 0};
.[$s | letter_grade] += 1
);