Selectively replace multiple instances of a character within a string: Difference between revisions
Selectively replace multiple instances of a character within a string (view source)
Revision as of 18:04, 28 July 2022
, 1 year ago→{{header|Haskell}}
Line 158:
nthCharsReplaced ruleMap = snd . mapAccumL go M.empty
where
go a c =
Just ds ->
let i = fromMaybe 0 (M.lookup c a)
in ( M.insert c (succ i) a,
else c
)
▲ | otherwise = (a, c)
▲ | i < length deltas = fromMaybe c (deltas !! i)
--------------------------- TEST -------------------------
|