Selectively replace multiple instances of a character within a string: Difference between revisions
Content added Content deleted
Line 237: | Line 237: | ||
// A string defined by replacements specified for |
// A string defined by replacements specified for |
||
// the nth instances of various characters. |
// the nth instances of various characters. |
||
s => |
s => mapAccumL( |
||
(a, c) => c in ruleMap ? (() => { |
|||
const |
|||
i = a[c] || 0, |
|||
ds = ruleMap[c]; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
})() : [a, c]; |
|||
⚫ | |||
}; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
// ---------------------- TEST ----------------------- |
// ---------------------- TEST ----------------------- |