Step: Order: sort_by, unique

Order: sort_by, unique

  • sort_by(f) sorts an array by the value of f (ascending).
  • sort sorts scalars directly; unique sorts and dedupes; reverse flips order.
sort_by(.price)
[3,1,2,1] | unique     # => [1,2,3]

Your turn: sort the products by price, then list just their names (cheapest first).

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:
[
  "Pen",
  "Notebook",
  "Widget",
  "Gadget"
]
Step 20 of 27