Skip to content

Instantly share code, notes, and snippets.

@tommyp
Last active March 6, 2018 14:40
Show Gist options
  • Save tommyp/bcdd6eb6fed3ff9d272d6f804f1a0f43 to your computer and use it in GitHub Desktop.
Save tommyp/bcdd6eb6fed3ff9d272d6f804f1a0f43 to your computer and use it in GitHub Desktop.
# 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