Selectively replace multiple instances of a character within a string: Difference between revisions

m
(→‎{{header|JavaScript}}: Added a variant – expressed in terms of a map-accumulation.)
Line 204:
return mapAccumL(a => c => {
const
i = (a[c] || 0),
ds = subs[c];
 
return [
Object.assign(a, {[c]: 1 + i}),
(ds && ds[i]) ? (
ds[i].trim() || c
) : c
Line 227:
acc => xs => [...xs].reduce(
([a, bs], x) => second(
v => bs[.concat(..bs, v)]
)(
f(a)(x)
Line 233:
[acc, []]
);
 
 
// second :: (a -> b) -> ((c, a) -> (c, b))
9,655

edits