I recently started working with AngularJS and have found it to be pretty powerful tool for creating dynamic and interactive webpages. One of my little projects involves a random pizza toppings selector, so I decided to take the PHP version I built a few years ago, translate it to Angular, and make some improvements.
For my project to work, I first need data. I need to know what toppings my local pizza joints are offering. I assembled my favorite spots into a json file and linked that up to my app. I then decide what type of topping orientations people might like: All Cheese, All Meat, All Veggies, Half and Half, Totally Random, Meat Heavy, and Veggie Heavy.
Each of these orientations pose certain challenges. For example, if a user chooses to have Half Veggies and Half Meat, but they also select an odd number of toppings, we still want the application to work, without any additional input from the user. For this case, we would want to choose a dominant topping-type randomly so that if the user selects 5 toppings, they could get 3 meat and 2 veggie, or 2 meat and 3 veggie.
The biggest challenge, however, came after a round of initial testing. It was discovered that one particular favorite pizza joint offered three types of chicken toppings: BBQ, Grilled, and Spicy. It was decided, after multiple cases in which two or more chicken toppings were chosen by the randomizer, that the design could not allow for totally random toppings: Nobody wants 3 types of chicken on their pizza. So I set about researching and implementing Levenshtein’s Distance Algorithm. This algorithm measures the distance difference in words. I made a few tiny modifications to my own toppings loop and succeeded in eliminating all “too-similar” toppings from a single pizza. Further, the return percentage value does not affect vegetables with similar titling, such as “Fresh Mushrooms” and “Fresh Spinach.” Both are capable of appearing on the same pizza despite the similarity in the word “Fresh”.
Anyway, all that is to say, Pizza is delicious. Please use my testpage to create a random selection of pizza toppings. Note: The “Cowabunga!” button doesn’t work yet — it will soon!