-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
27 lines (24 loc) · 922 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function X(rawstr, insertionPoints, insertionStrings) {
if (insertionPoints.length === 0) {
return rawstr;
}
let insertIndex = insertionPoints[0];
let insertStr = insertionStrings[0]; // 插入的字符串
let firstPart = rawstr.slice(0, insertIndex);
let secondPart = rawstr.slice(insertIndex);
let newRawStr = firstPart + insertStr + secondPart;
let offset = insertStr.length;
let newInsertionPoints, newInsertionStrings;
if (insertionPoints.length > 1) {
newInsertionPoints = insertionPoints.slice(1).map((p) => p + offset);
newInsertionStrings = insertionStrings.slice(1);
} else {
newInsertionPoints = [];
newInsertionStrings = [];
}
return X(newRawStr, newInsertionPoints, newInsertionStrings); // Updated line
}
let rawstr = 'hello , are you ok';
let insertionPoints = [5, 7];
let result = X(rawstr, insertionPoints, ['🐰', '🐱']); // Removed unnecessary argument
console.log(result);