Hey guys, am trying to solve a recursive problem with this problem statement:
Write a function ice_cream_shop (flavors, favorite) that takes in an array of ice cream flavors available at the ice cream shop, as well as the user’s favorite ice cream flavor. Recursively find out whether or not the shop offers their favorite flavor.
I offered up this attempt but it does not seem to work, any guidance please?
My Attempt
function ice_cream_shop(stockArr, userRequest) {
if (stockArr.length <= 0) return false;
if (stockArr[stockArr.length - 1] === userRequest) {
return true;
} else {
stockArr.pop();
ice_cream_shop(stockArr);
}
}
Thanks a lot @camperextraordinaire, the challenges am facing are in Ruby which I heard has implicit return from App Academy Open Curriculum. I guess the syntax stuck on me after seeing their lectures that did not use the return statement in their recursive code.
Do you think this is the best solution though, how would you solve it?