Skip to content

Commit 389391a

Browse files
committed
Refactor jq commands for consistency in script files
1 parent df8bd9f commit 389391a

9 files changed

Lines changed: 9 additions & 9 deletions

File tree

jq/script-01.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -euo pipefail
55
# The input for this script is the person.json file.
66
# TODO: Write a command to output the name of the person.
77
# Your output should be exactly the string "Selma", but should not contain any quote characters.
8-
jq -r .name person.json
8+
jq -r '.name' person.json

jq/script-04.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set -euo pipefail
66
# TODO: Write a command to output just the names of each player, one per line.
77
# Your output should contain 6 lines, each with just one word on it.
88
# Your output should not contain any quote characters.
9-
jq -r .[].name scores.json
9+
jq -r '.[].name' scores.json

jq/script-05.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -euo pipefail
55
# The input for this script is the scores.json file.
66
# TODO: Write a command to output the names of each player, as well as their city.
77
# Your output should contain 6 lines, each with two words on it.
8-
jq -r '.[] | "\(.name) \(.city)"' scores.json
8+
jq -r '.[] | .name + " " + .city' scores.json

jq/script-06.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set -euo pipefail
66
# TODO: Write a command to output just the names of each player along with the score from their first attempt.
77
# Your output should contain 6 lines, each with one word and one number on it.
88
# The first line should be "Ahmed 1" with no quotes.
9-
jq -r '.[] | "\(.name) \(.scores[0])"' scores.json
9+
jq -r '.[] | .name + " " + (.scores[0] | tostring)' scores.json

jq/script-07.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set -euo pipefail
66
# TODO: Write a command to output just the names of each player along with the score from their last attempt.
77
# Your output should contain 6 lines, each with one word and one number on it.
88
# The first line should be "Ahmed 4" with no quotes.
9-
jq -r '.[] | "\(.name) \(.scores[-1])"' scores.json
9+
jq -r '.[] | .name + " " + (.scores[-1] | tostring)' scores.json

jq/script-08.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set -euo pipefail
66
# TODO: Write a command to output just the names of each player along with the number of times they've played the game.
77
# Your output should contain 6 lines, each with one word and one number on it.
88
# The first line should be "Ahmed 3" with no quotes.
9-
jq -r '.[] | "\(.name) \(.scores | length)"' scores.json
9+
jq -r '.[] | .name + " " + (.scores | length | tostring)' scores.json

jq/script-09.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set -euo pipefail
66
# TODO: Write a command to output just the names of each player along with the total scores from all of their games added together.
77
# Your output should contain 6 lines, each with one word and one number on it.
88
# The first line should be "Ahmed 15" with no quotes.
9-
jq -r '.[] | "\(.name) \(.scores | add)"' scores.json
9+
jq -r '.[] | .name + " " + (.scores | add | tostring)' scores.json

jq/script-10.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -euo pipefail
55
# The input for this script is the scores.json file.
66
# TODO: Write a command to output the total of adding together all players' first scores.
77
# Your output should be exactly the number 54.
8-
jq '[.[] | .scores[0]] | add' scores.json
8+
jq '[.[].scores[0]] | add' scores.json

jq/script-11.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -euo pipefail
55
# The input for this script is the scores.json file.
66
# TODO: Write a command to output the total of adding together all scores from all games from all players.
77
# Your output should be exactly the number 164.
8-
jq '[.[] | .scores[]] | add' scores.json
8+
jq '[.[].scores[]] | add' scores.json

0 commit comments

Comments
 (0)