Last active
March 6, 2018 14:40
-
-
Save tommyp/bcdd6eb6fed3ff9d272d6f804f1a0f43 to your computer and use it in GitHub Desktop.
This file contains 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 have an list of maps : | |
sentence_list = [ | |
%{ | |
keywords: ~w(cat), | |
sentence: "I'm a cat person", | |
}, | |
%{ | |
keywords: ~w(dog), | |
sentence: "I'm a dog person", | |
} | |
] | |
# And a string: | |
statement = "My Cat is called Larry, but I don't have a Dog." | |
# I need to find the first map in the list, which contains the first matching word. | |
# So far I have: | |
words_list = statement | |
|> String.downcase | |
|> String.split | |
# I'm not quite sure how to iterate over the words list and get the matching map from the sentence list. | |
# I should get back "I'm a cat person" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment