Created
February 25, 2018 02:59
-
-
Save dance2die/adc7daccc0b290e238de5f254a7bcd8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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