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

m
Line 237:
// A string defined by replacements specified for
// the nth instances of various characters.
s => {mapAccumL(
const go = (a, c) => c in ruleMap ? (() => {
c in ruleMap ? (() => {const
consti = a[c] || 0,
ids = aruleMap[c] || 0,;
ds = ruleMap[c];
 
return [
Object.assign(a, {[c]: 1 + i}),
i < ds.length ? (
ds[i] || c
) : c
];
})() : [a, c];
 
return mapAccumL(go)({})([...s])[1].join("");
};
 
return [
Object.assign(a, {[c]: 1 + i}),
i < ds.length ? (
ds[i] =|| ruleMap[c];
) ds[i] ||: c
) : c];
})() : [a, c];
return mapAccumL(go)({})([...s])[1].join("");
 
// ---------------------- TEST -----------------------
9,655

edits