pekinese Posted July 18, 2017 Report Posted July 18, 2017 I tried to get the highest price of today for an array of items.My code until now: opskins.getPriceList(730, function(err, prices) { if (err) console.log("error!"); if(prices){ highest_price = Infinity; for (var item in prices) { if(keys.includes(item)){ //how to continue now? } } } });Any suggestions how to get only the "latest" price for each item, so I can compare and get the highest price of ALL items for only today? In the end I only need to get one value, for example for this JSON object: "item1": {"2017-07-17": {"price": 800},"2016-07-16": {"price": 453},"2016-07-15": {"price": 435}},"item2": {"2017-07-17": {"price": 622},"2016-07-16": {"price": 643},"2016-07-15": {"price": 593}} It would return 800. Quote
Dr. McKay Posted July 18, 2017 Report Posted July 18, 2017 https://github.com/OPSkins/node-opskins-api#getlowestpricesappid-callback may be what you're looking for. Quote
pekinese Posted July 18, 2017 Author Report Posted July 18, 2017 https://github.com/OPSkins/node-opskins-api#getlowestpricesappid-callback may be what you're looking for.I need to get the highest price See post above. Quote
Dr. McKay Posted July 18, 2017 Report Posted July 18, 2017 Getting the highest price would be pointless; you'd basically always just get $99,999.99. Quote
pekinese Posted July 19, 2017 Author Report Posted July 19, 2017 Getting the highest price would be pointless; you'd basically always just get $99,999.99.See the example above. In this case I would need to get 800. Quote
Dr. McKay Posted July 19, 2017 Report Posted July 19, 2017 You'd want to foreach loop over the object and pull the maximum value, just like you're foreach looping prices to get the item. Quote
pekinese Posted July 20, 2017 Author Report Posted July 20, 2017 But how to get the date which is the "key", I would need to get only the first entry of each price "array". How to do so, any way without using the date, because as I've seen the first date isn't always the "current" date, isn't it? Quote
Dr. McKay Posted July 20, 2017 Report Posted July 20, 2017 If you only want the latest, you could get the keys using Object.keys, sort it (YYYY-MM-DD sorts alphabetically quite nicely), then pull the first/last element (depending on how you sorted it). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.