Created
October 2, 2017 20:10
-
-
Save KimSarabia/ccea367114d695ea24f30174d979bdf9 to your computer and use it in GitHub Desktop.
For-In Example - Comparing Two Objects
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
//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