Created
September 3, 2025 03:26
-
-
Save AbeEstrada/9e22122c8ba54fa5240c4e7caa6d7d01 to your computer and use it in GitHub Desktop.
Exercise: Hash Tables Ice Cream Parlor
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
function whatFlavors(cost, targetAmount) { | |
const priceToIndexMap = new Map(); | |
for (const [currentIndex, currentPrice] of cost.entries()) { | |
const neededPrice = targetAmount - currentPrice; | |
const displayIndex = currentIndex + 1; | |
if (priceToIndexMap.has(neededPrice)) { | |
const firstFlavorIndex = priceToIndexMap.get(neededPrice); | |
console.log(`${firstFlavorIndex} ${displayIndex}`); | |
return; | |
} | |
priceToIndexMap.set(currentPrice, displayIndex); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment