Created
December 28, 2014 23:08
-
-
Save jaimeagudo/85ae46bf59b32218751e to your computer and use it in GitHub Desktop.
Top 20 pizzas
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
//require underscore & jquery | |
var pizzas={}; | |
$.ajax({ | |
type: 'GET', | |
url: 'http://files.olo.com/pizzas.json', | |
async: false, | |
contentType: "application/json", | |
dataType: 'json', | |
success: function (data) { | |
pizzas=data; | |
}, | |
error: function (e) { | |
alert('error'); | |
console.log(e); | |
} | |
}); | |
var sortedByTimesOrdered=_.chain(pizzas) | |
.map(function(pizza) { return pizza.toppings; }) | |
.countBy(function(toppings){ return toppings;}) | |
.map(function(value,key){return {toppings: key.split(","), timesOrdered: value}; } ) | |
.sortBy('timesOrdered') | |
.value().reverse(); | |
console.log(JSON.stringify(sortedByTimesOrdered.slice(0,20))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment