Created
November 23, 2018 18:05
-
-
Save lnikon/2a21f40c77cfc3bd14b903bcb117e703 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
1) Find the last element of a list. | |
xs = [1, 2, 3, 4] | |
last xs | |
2) Find the last but one element of a list. | |
xs = [1, 2, 3, 4] | |
last (init xs) | |
3) Find the K'th element of a list. The first element in the list is number 1. | |
xs = [1, 2, 4, 3, 5, 6, 8, 7] | |
elementAt xs k = if k > 0 then elementAt (tail xs) (k - 1) else (last (reverse xs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment