Birmingham | 2026-MAR-SDC | Joy Opachavalit | Sprint 2 | jq#379
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
Solution looks good. I just have a question.
| # The input for this script is the scores.json file. | ||
| # TODO: Write a command to output the total of adding together all scores from all games from all players. | ||
| # Your output should be exactly the number 164. | ||
| jq -r 'map(.scores) | add | add' scores.json |
There was a problem hiding this comment.
Can you explain how the two add works in the query? That is, why "add" twice?
There was a problem hiding this comment.
Data shape: scores.json is an array of player objects where each scores value is an array (e.g. [[1,10,4],[22,9,6],...]).
map(.scores) produces an array of arrays: [[1,10,4],[22,9,6],...].
First add: when add is given an array of arrays it concatenates them into one array: [1,10,4,22,9,6,...].
Second add: when add is given an array of numbers it returns their sum (i.e. 164).
So map(.scores) | add | add is: collect each player's scores then join into one big list then sum the numbers.
|
Closing PR because the SDC run has finished. Feel free to re-open if you're still working on it. |
Learners, PR Template
Self checklist
Changelist
Completed all exercises