Last active
May 28, 2020 00:52
-
-
Save egalink/12d02377a4dfe36f620bc36f5312ce1f 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
| var collection = [ | |
| {item: "lapiz", cost: 10.2, vendor: "mari"}, | |
| {item: "lapiz", cost: 11.2, vendor: "maris"}, | |
| {item: "lapiz", cost: 8.24, vendor: "maris"}, | |
| {item: "lapiz", cost: 8.232, vendor: "maris"}, | |
| {item: "lapiz", cost: 8.23198, vendor: "maris"}, | |
| {item: "lapiz", cost: 8.23199, vendor: "maris"}, | |
| {item: "lapiz", cost: 8.25, vendor: "maris"}, | |
| {item: "lapiz", cost: 8.256, vendor: "maris"}, | |
| {item: "lapiz", cost: 9, vendor: "mariss"}, | |
| {item: "lapiz", cost: 900, vendor: "mariss"}, | |
| {item: "lapiz", cost: 9.1, vendor: "mariss"}, | |
| {item: "lapiz", cost: 9.02, vendor: "mariss"} | |
| ]; | |
| function withMinCost (collection) { | |
| // | |
| var dictionary = {}; | |
| collection.forEach(function (obj) { | |
| var i = Number(obj.cost); | |
| if (! isNaN(i)) { | |
| dictionary[i] = obj; | |
| } | |
| }); | |
| var minCost = Object.keys(dictionary).sort(function (a, b) { return a - b }); | |
| return dictionary[minCost[0]]; | |
| } | |
| withMinCost(collection); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment