Last active
October 7, 2024 18:03
-
-
Save nichoth/dd132fe1c7ce958619faf51909e93915 to your computer and use it in GitHub Desktop.
Find how many ingredients you need to buy
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
// | |
// I always like an opportunity to use `Set` in JS. | |
// There should be `difference` and `intersection` operators | |
// in new environments, but my Node didn't have them, | |
// so we're doing it slightly more laboriously. | |
// (`node -v` = 20.16.0) | |
// | |
const recipe = ['eggs', 'flour', 'sugar', 'butter'] | |
const pantry = ['sugar', 'butter', 'milk'] | |
const both = new Set([...recipe, ...pantry]) | |
Array.from(both).length - pantry.length | |
// => 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment