I know I should be forgetting about iterating in functional languages, but I dont know how else to put forth my question.
If I have a list of integers arranged in ascending or descending order, and I have an arbitrary number that may or may not be present in the list, how can I loop over the list to find a number that is small than the given number and return that integer.
I just need to know how to go about it.
elemfunction work for you?elemdoesn't do what OP asked for.last . takeWhile (<= input) $ xs. To accommodate your latest requirement,let (a,b)=span(<= input) xs in head $ [input|null b]++[last a].