Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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