Created
April 14, 2020 22:34
-
-
Save atlc/5696c81d5be36b272c0c43469d59dad9 to your computer and use it in GitHub Desktop.
Retrieves a json body of the few thousand most common pizza topping combos. This fetches, flattens, and sorts the collection into a Map, and returns the top 20 individual toppings. Solution is 280B.
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
import f from 'node-fetch'; | |
let M=new Map(); | |
f('https://www.olo.com/pizzas.json').then(r=>r.json()).then(p=>{ | |
p.forEach(c=>[...c.toppings].forEach(c=>!M.has(c)?M.set(c,0):M.set(c,M.get(c)+1))); | |
console.log([...M.entries()].sort((a,b)=>a[1]>b[1]?-1:a[1]<b[1]?1:0).splice(0,20)); | |
}); | |
// Returns this: | |
/* | |
[ | |
[ 'pepperoni', 6334 ], | |
[ 'four cheese', 1610 ], | |
[ 'mozzarella cheese', 1460 ], | |
[ 'bacon', 1446 ], | |
[ 'beef', 1139 ], | |
[ 'sausage', 830 ], | |
[ 'mushrooms', 732 ], | |
[ 'italian sausage', 671 ], | |
[ 'black olives', 455 ], | |
[ 'chicken', 400 ], | |
[ 'pineapple', 359 ], | |
[ 'ham', 340 ], | |
[ 'jalapenos', 257 ], | |
[ 'green peppers', 205 ], | |
[ 'canadian bacon', 173 ], | |
[ 'diced white onions', 167 ], | |
[ 'cheddar cheese', 153 ], | |
[ 'diced tomatoes', 127 ], | |
[ 'alredo sauce', 126 ], | |
[ 'onions', 120 ] | |
] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment