Skip to content

Commit 2c5d529

Browse files
update
1 parent d52162b commit 2c5d529

8 files changed

Lines changed: 25 additions & 8 deletions

File tree

jq/script-01.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ 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 #we use '-r' to print the name without quotations
8+
# We use '-r' to print the name without quotations
9+
jq -r '.name' person.json

jq/script-02.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ set -euo pipefail
55
# The input for this script is the person.json file.
66
# TODO: Write a command to output the address of the person, all on one line, with a comma between each line.
77
# Your output should be exactly the string "35 Fashion Street, London, E1 6PX", but should not contain any quote characters.
8-
jq -r '.address | join(", ")' person.json # first it returns an array but we use join to add them toghether with a comma and a space
8+
9+
# first it returns an array but we use join to add them toghether with a comma and a space
10+
jq -r '.address | join(", ")' person.json

jq/script-03.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ 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, then a comma, then their profession.
77
# Your output should be exactly the string "Selma, Software Engineer", but should not contain any quote characters.
8-
jq -r '[.name, .profession] | join(", ")' person.json # join works on arrays thats why we need to to put values of name and profession in a array to be able to use join
8+
9+
# Join works on arrays thats why we need to to put values of name and profession in a array to be able to use join
10+
jq -r '[.name, .profession] | join(", ")' person.json

jq/script-04.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ 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 # we get the "name" from each object in the array and print it '.[].name'
9+
10+
# we get the "name" from each object in the array and print it '.[].name'
11+
jq -r '.[].name' scores.json

jq/script-06.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ 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]] | join(" ")' scores.json # .scores[index 1]
9+
10+
# .scores[index 1]
11+
jq -r '.[] | [.name, .scores[0]] | join(" ")' scores.json
12+

jq/script-07.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ 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]] | join(" ")' scores.json # .scores[-1] = last index
9+
10+
# .scores[-1] = last index
11+
jq -r '.[] | [.name, .scores[-1]] | join(" ")' scores.json

jq/script-08.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ 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)] | join(" ")' scores.json # (.scores | length) = length of array
9+
10+
# (.scores | length) = length of array
11+
jq -r '.[] | [.name, (.scores | length)] | join(" ")' scores.json

jq/script-09.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ 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)] | join(" ")' scores.json # (.scores | add) = adding each index of this array
9+
10+
# (.scores | add) = adding each index of this array
11+
jq -r '.[] | [.name, (.scores | add)] | join(" ")' scores.json
12+

0 commit comments

Comments
 (0)