Find And Replace in String LeetCode solution in JavaScript

1
var findReplaceString = function (s, indices, sources, targets) {
2
let res = s.split("");
3

4
for (let i = 0; i < indices.length; i++) {
5
let index = indices[i];
6
let str = sources[i];
7

8
if (s.slice(index, index + str.length) == str) {
9
res[index] = targets[i];
10
for (let j = 1; j < str.length; j++) {
11
res[(index += 1)] = "";
12
}
13
}
14
}
15

16
return res.join("");
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0