Created
June 13, 2020 14:30
-
-
Save geomago/0193de584970749880ebb5f747c21827 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 findCheapest(orders) { | |
| var cheapest = 999999999; | |
| for (i=0; i<orders.length; i++) { | |
| cheapest = Math.min(cheapest, findCheapestItem(orders[i].items) ); | |
| } | |
| return cheapest; | |
| } | |
| function findCheapestItem(items) { | |
| var cheapest = 999999999; | |
| for (i=0; i<items.length; i++) { | |
| cheapest = Math.min(cheapest,items[i].cost); | |
| } | |
| return cheapest; | |
| } | |
| var orders = [{id:1, items: [{cost:100.00},{cost: 95.00}]}, | |
| {id:2, items: [{cost:90.00},{cost: 120.00}]} | |
| ]; | |
| alert( findCheapest(orders) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment