Skip to content

Instantly share code, notes, and snippets.

@jaimeagudo
Created December 28, 2014 23:08
Show Gist options
  • Save jaimeagudo/85ae46bf59b32218751e to your computer and use it in GitHub Desktop.
Save jaimeagudo/85ae46bf59b32218751e to your computer and use it in GitHub Desktop.
Top 20 pizzas
//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