Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created February 25, 2018 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/adc7daccc0b290e238de5f254a7bcd8b to your computer and use it in GitHub Desktop.
Save dance2die/adc7daccc0b290e238de5f254a7bcd8b to your computer and use it in GitHub Desktop.
function sortByAscendingDemo(orders) {
// Sorting works by comparing two values in a callback.
// When o1.quantity < 0, then o1 comes before o2.
// When o2.quantity < 0, then o2 comes before o1.
// When o1.quantity === o2.quantity then no change is needed
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
var oderedOrders = orders.sort((o1, o2) => o1.quantity - o2.quantity);
printOrders(oderedOrders);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment