-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
23 lines (21 loc) · 530 Bytes
/
index.js
File metadata and controls
23 lines (21 loc) · 530 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module.exports = function (original, delta) {
let result = '',
index = 0;
// According to latest jsperf tests, there's no need to cache array length
for (let i = 0; i < delta.length; i++) {
const item = delta[i],
operation = item[0],
value = item[1];
if (operation == -1) {
// DELETE
index += value;
} else if (operation == 0) {
// KEEP
result += original.slice(index, (index += value));
} else {
// INSERT
result += value;
}
}
return result;
};