HRM-10/HRM.UI/ClientApp/replaceCloseSolution.txt
Mohaimen Hasan 838b8d4480 first commit
2026-11-03 13:06:00 +06:00

35 lines
862 B
Plaintext

1. Solution 01
const replaceClose = (
index,
string,
close,
replace,
head = string.substring(0, index) + replace,
tail = string.substring(index + close.length),
next = tail.indexOf(close)
) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace))
) => {
let result = '';
do {
const head = string.substring(0, index) + replace;
string = string.substring(index + close.length);
index = string.indexOf(close);
result += head;
} while (index >= 0);
return result + string;
}
2. Solution 02
const replaceClose = (
index,
string,
close,
replace,
head = string.substring(0, index) + replace,
tail = string.substring(index + close.length),
next = tail.indexOf(close)
) => {
console.log(index, string, close, replace);
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
}