Created
July 25, 2018 03:31
-
-
Save mauricioabreu/8fdb64bef6a938dd1e34ac15e9268d4d to your computer and use it in GitHub Desktop.
Using Elixir pattern matching to check if a list has an event length of elements
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
// Write a function even_length? that uses pattern matching only to return false | |
// if the list you pass it has an odd number of elements, true otherwise. | |
def even_length?([_, _ | t]) do | |
even_length?(t) | |
end | |
def even_length?([_ | []]) do | |
false | |
end | |
def even_length?([]) do | |
true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Even better: