Skip to content

Instantly share code, notes, and snippets.

@KimSarabia
Created October 2, 2017 20:10
Show Gist options
  • Save KimSarabia/ccea367114d695ea24f30174d979bdf9 to your computer and use it in GitHub Desktop.
Save KimSarabia/ccea367114d695ea24f30174d979bdf9 to your computer and use it in GitHub Desktop.
For-In Example - Comparing Two Objects
//Favorite Pete the Baker Solution
//https://www.codewars.com/kata/525c65e51bf619685c000059/solutions/javascript
function cakes(recipe, available) {
var numCakes = [];
for(var key in recipe){
if(recipe.hasOwnProperty(key)){
if(key in available){
numCakes.push(Math.floor(available[key] / recipe[key]));
}else{
return 0;
}
}
}
return Math.min.apply(null, numCakes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment