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 12:56, 28 July 2022
, 1 year ago→{{header|JavaScript}}
(→{{header|JavaScript}}: Added a variant – expressed in terms of a map-accumulation.) |
|||
Line 204:
return mapAccumL(a => c => {
const
i =
ds = subs[c];
return [
Object.assign(a, {[c]: 1 + i}),
ds[i].trim() || c
) : c
Line 227:
acc => xs => [...xs].reduce(
([a, bs], x) => second(
v =>
)(
f(a)(x)
Line 233:
[acc, []]
);
// second :: (a -> b) -> ((c, a) -> (c, b))
|