-
-
Notifications
You must be signed in to change notification settings - Fork 13
London | Samira Hekmati | Module Tools | Week 2 | jq #42
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?
Changes from 12 commits
5dc1072
e09a003
9ab104f
a7caeab
85c82b3
b573926
619b4c9
2122968
8bec120
5d9f6b1
b59299c
ccbdcc5
62f7867
5018472
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
[{"name": "Ahmed", "city": "London", "scores": [1, 10, 4]}, {"name": "Basia", "city": "London", "scores": [22, 9, 6]}, {"name": "Mehmet", "city": "Birmingham", "scores": [3, 12, 17]}, {"name": "Leila", "city": "London", "scores": [1]}, {"name": "Piotr", "city": "Glasgow", "scores": [15, 2, 25, 11, 8]}, {"name": "Chandra", "city": "Birmingham", "scores": [12, 6]}] | ||
[ | ||
{ "name": "Ahmed", "city": "London", "scores": [1, 10, 4] }, | ||
{ "name": "Basia", "city": "London", "scores": [22, 9, 6] }, | ||
{ "name": "Mehmet", "city": "Birmingham", "scores": [3, 12, 17] }, | ||
{ "name": "Leila", "city": "London", "scores": [1] }, | ||
{ "name": "Piotr", "city": "Glasgow", "scores": [15, 2, 25, 11, 8] }, | ||
{ "name": "Chandra", "city": "Birmingham", "scores": [12, 6] } | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ set -euo pipefail | |
# TODO: Write a command to output just the names of each player along with the score from their last attempt. | ||
# Your output should contain 6 lines, each with one word and one number on it. | ||
# The first line should be "Ahmed 4" with no quotes. | ||
|
||
jq -r '.[] | .scores[-1] as $scores | "\(.name) \($scores)" ' scores.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get what you're trying to say. The variable |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ set -euo pipefail | |
# TODO: Write a command to output just the names of each player along with the total scores from all of their games added together. | ||
# Your output should contain 6 lines, each with one word and one number on it. | ||
# The first line should be "Ahmed 15" with no quotes. | ||
|
||
jq -r '.[] | "\(.name) \([.scores[]] | add)"' scores.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The part
|
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.
In script-03 you used
join
and here you used string interpolation - both work, and both could be used in both places - do you have any thoughts on which you prefer / which is more clear?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.
Thank you so much Daniel, @illicitonion for your feedback! I agree that both methods join(", ") and string interpolation are valid, and it's interesting to think about their usage in different contexts.
For example in script-03, I chose join(", ") as I felt it was a cleaner way to handle the array of values (in this case, name and profession). It also keeps the structure clear by dealing with the array directly. On the other hand, in script-05, I used string interpolation because it was more intuitive for handling the dynamic insertion of values within a string.
I don't have a strong preference for one over the other, but I can see how string interpolation may be more flexible, especially if we were working with more complex strings or needing more control over formatting.
I think, if clarity and simplicity are the primary goals, join(", ") works well for array type of structures, while string interpolation might be more readable when we're dealing with individual elements or values.