In Reverse explainer


#1

The aim of this puzzle: Sort the groceries array from highest to lowest price.

Walkthrough of the solution: When the starter code runs, it prints out all of the grocery items. The order of items increases in price. To reverse the order of the array, you can use the .reverse() method.

Attach .reverse() to groceries before printing the array.

Sample code solution:
(Tap below to reveal)

import { groceries } from 'grasshopper.store';
function printItem(item) {
  console.log(item.name + ': $' + item.price);
}
groceries.reverse();
groceries.forEach(printItem);

JavaScript Concepts: Binary Expression (+ concatenation), console.log(), .forEach(), import, .reverse()


#2