I am new to elixir I know how to solve the issue in JavaScript, but i am having a hard time converting it to elixir solution.
I am trying to take a list in and output the words the occur more than once
const str = "This is the state of education? is It?"
words = str.split(" ");
const data = new Set(words.map((word) => {
if(words.filter((value) => value ==
word).length > 1){
return word
}
}).filter(value => value != undefined)
)
// Set(1) {'is'}
I have been trying to do this in Elixir but I keep failing at it because values are immutable.
defmodule Test do
def find_duplicate_words(sentence) do
words = String.split(String.downcase(sentence))
ls = [1,2]
Enum.map(words, fn word ->
# if "fox" == word do
[ls | word]
# end
end
)
IO.puts(ls)
IO.puts(length(words))
end
end
sentence = """
This is the state of education? is It?
"""
# returns ["is"] <-- return this
Test.find_duplicate_words(sentence)
Can anyone show me how to do this?