I have a string 3-5,10-15,20 and I want to insert p before every number. I wanted to just find each '-' and ',' and insert a 'p' after each one, and then one at the beginning.
Looping over it requires manipulating the string you're looping over, which wasn't working quite well for me. I feel like this is such a simple task, but I'm getting stuck. Any help would be appreciated.
The final result should look like p3-p5,p10-p15,p20.
This is what I tried:
input = `p${input}`;
for (let i = 0; i < input.length; i++) {
if (input[i] === '-' || input[i] === ',') {
input = `${input.slice(0, i + 1)}p${input.slice(i + 1)}`;
}
}