There's probably a much simpler way to solve it, but hey, I basically know how to do pattern matching and recursion, so there we go:
defmoduleLikedodefwho_likes(list)docount=Enum.count(list)_who_likes(list,count-2)|>_add_likes(count)|>IO.putsenddefp_add_likes(x,n)when(n<2),do:"#{x} likes this"defp_add_likes(x,_),do:"#{x} like this"defp_who_likes([],_),do:"no one"defp_who_likes([a|[]],_),do:adefp_who_likes([a,b|[]],_),do:"#{a} and #{b}"defp_who_likes([a,b,c|[]],_),do:"#{a}, #{b} and #{c}"defp_who_likes([a,b|_tail],count),do:"#{a}, #{b} and #{count} others"end
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Elixir
There's probably a much simpler way to solve it, but hey, I basically know how to do pattern matching and recursion, so there we go: