September 2017
Beginner to intermediate
396 pages
9h 46m
English
-- Group elements in groups of twos, but when we group it we keep them -- sorted. group2 :: Ord a => [a] -> [[a]] group2 [] = [] -- A single element is already sorted. group2 (x:[]) = [[x]] -- Create groups of two and sort them group2 (x:y:xs) = (sortPair x y) : group2 xs where sortPair x y | x >= y = y : x : [] | otherwise = x : y : []
Read now
Unlock full access