Last active
October 16, 2015 20:03
-
-
Save bignimbus/4e61d7bade1ca0e62cfd to your computer and use it in GitHub Desktop.
Math.PIE() - a proposed ECMAScript 7 feature
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
// in order for this to work, you need a yummly dev account. | |
function makePie (response) { | |
var match = JSON.parse(response).matches[0], | |
yourPie = ["you could bake a delicious ", | |
match.recipeName, | |
" using "]; | |
match.ingredients.forEach(function (ingredient) { | |
yourPie.push("[" + ingredient + "]"); | |
}); | |
return yourPie.join(''); | |
} | |
Math.PIE = function (ingredients) { | |
ingredients = (ingredients instanceof Array ? ingredients.join('+') : ingredients) || ""; | |
var req = new XMLHttpRequest(); | |
req.onreadystatechange = function () { | |
if (req.readyState == 4 && req.status == 200) { | |
console.log(makePie(req.responseText)); | |
} | |
}; | |
req.open("GET", | |
"https://api.yummly.com/v1/api/recipes?_app_id=##YUMMLY_API_ID##&_app_key=##YUMMLY_API_KEY##&q=pie+" | |
+ ingredients, | |
false); | |
req.send(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment