-
-
Notifications
You must be signed in to change notification settings - Fork 42
London | 25-SDC-July | Andrei Filippov | Sprint 2 | jq exercises #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
LonMcGregor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work on this sprint. Your solutions work, but there may be ways they could be simplified
jq/script-11.sh
Outdated
| # 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 '[.[].scores] | add | add' scores.json No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably simplify this command to only need a single add. Can you figure out how to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, the only solution that comes to my mind is to use flatten method
jq/script-05.sh
Outdated
| # The input for this script is the scores.json file. | ||
| # TODO: Write a command to output the names of each player, as well as their city. | ||
| # Your output should contain 6 lines, each with two words on it. | ||
| jq -r '.[]| {"name":.name, "city":.city} | join(" ")' scores.json No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your solution of constructing a new json object and joining it works, but you could probably simplify it a bit. Do you know how to directly build a string in a jq command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, cool. I didn't know that I can concatenate strings in jq, but now I know that I need to use + operator to do it.
|
Yes, string concatenation makes things a bit simpler. Good work using that. As for your solution using Remember what the |
|
Great work solving this - you are done with this sprint task now |
Learners, PR Template
Self checklist
Changelist
done exercises
Questions
no questions