2010-04-01から1日間の記事一覧

数字文字列にカンマを入れる

ワンライナーっぽく出来た。 Prelude> let addComma numStr = concat $ snd $ foldr (\x t ->(fst t + 1,(if fst t `mod` 3 == 0 && fst t /= 0 then (x++",") else x):snd t)) (0,[]) [[x]|x <-numStr] Prelude> addComma "1234" "1,234" Prelude> addComma…