Step: Transform with map()

Transform with map()

map(f) applies f to every element of an array and returns a new array. It's shorthand for [ .[] | f ].

map(.price)            # array of prices
map(.price * 1.1)      # 10% markup on each

Pitfall: map expects an array as input (not a stream). Use [ .[] | f ] if you're mid-stream.

Your turn: produce an array of every product's price.

Input:
[
  {
    "name": "Widget",
    "price": 25,
    "category": "tools"
  },
  {
    "name": "Gadget",
    "price": 80,
    "category": "tools"
  },
  {
    "name": "Notebook",
    "price": 12,
    "category": "office"
  },
  {
    "name": "Pen",
    "price": 3,
    "category": "office"
  }
]
Expected:
[
  25,
  80,
  12,
  3
]
Step 18 of 27