mykatas/haskell/13_weight_for_weight.hs

15 lines
390 B
Haskell

module Codewars.G964.WeightSort where
import Data.Char (digitToInt)
import Data.List (sortBy)
import Data.Ord (comparing)
orderWeight :: [Char] -> [Char]
orderWeight = unwords . sortBy cmpWeights . words
cmpWeights :: [Char] -> [Char] -> Ordering
cmpWeights = comparing weights
weights :: [Char] -> (Int, [Char])
weights s = (sum . map digitToInt $ s, s)