Last active
January 3, 2018 03:24
-
-
Save thecolorblue/e6dd2125b30d3f48088eb3fec7553bce 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
| fetch('http://files.olo.com/pizzas.json') | |
| .catch(e=>console.error(e.message)) | |
| .then(r=>r.json()) | |
| .then((sales)=>sales.reduce((totals, sale)=>{ | |
| var topCombo = sale.toppings.join(' - '); | |
| if (totals[topCombo] > 0) totals[topCombo]++; | |
| else totals[topCombo] = 1; | |
| return totals; | |
| },{})) | |
| .then(r=>Object.keys(r).map(toppings=>{ return { toppings:toppings, total: r[toppings] }})) | |
| .then(list=>list.sort((a, b)=> b.total - a.total)) | |
| .then(list=>list.splice(0, 20)) | |
| .then(list=>list.map((t, index)=>{ return { toppings: t.toppings, total: t.total, rank: index + 1 } })) | |
| .then(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment