commit 4df569454b27b30580c50f678208c554e3486f02 parent d423031a1ac9fa739fe66dad947fb0e05b5875bf Author: Jared Tobin <jared@luminal.io> Date: Fri, 26 Jun 2015 13:39:30 +1200 Add string replace exercise. Diffstat:
A | 20150522_stringreplace/Replace.hs | | | 10 | ++++++++++ |
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/20150522_stringreplace/Replace.hs b/20150522_stringreplace/Replace.hs @@ -0,0 +1,10 @@ + +module Replace where + +stringReplace :: String -> String -> String -> String +stringReplace pat rep = foldr alg [] where + patLength = length pat + alg c acc + | take patLength (c:acc) == pat = rep ++ drop patLength (c:acc) + | otherwise = c : acc +