inserstInBtwn
Tue Jan 04 2022 17:56:03 GMT+0000 (Coordinated Universal Time)
Saved by
@shadow337
function insertInBtwn(chars, d1, d2, insertion) {
//to use splice to insert, you will need 4 things (the array to work on and 3 parameters):
// array of characters (chars)
chars = chars.split("");
// the starting index (leftDelimIndex + 1)
const leftDelimIndex = chars.indexOf(d1);
const rightDelimIndex = chars.indexOf(d2);
// the range to delete (rightDelimIndex - leftDelimIndex - 1)
// the thing to insert (insertion)
chars.splice(
leftDelimIndex + 1,
rightDelimIndex - leftDelimIndex - 1,
insertion
);
return chars.join("");
}
content_copyCOPY
Comments