• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

YuJianrong / fast-array-diff / 15644705543

13 Jun 2025 09:58PM UTC coverage: 100.0%. Remained the same
15644705543

push

github

YuJianrong
chore: update Node.js version to 22.16.0 in GitHub Actions workflow

143 of 147 branches covered (97.28%)

193 of 193 relevant lines covered (100.0%)

2010.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/diff/apply.ts
1
import * as patch from './patch';
2

3
export type ApplyItem<T> =
4
  | patch.PatchItem<T>
5
  | {
6
      type: 'remove';
7
      oldPos: number;
8
      newPos: number;
9
      length: number;
10
    };
11

12
export type Apply<T> = ApplyItem<T>[];
13

14
export function applyPatch<T>(a: T[], patch: Apply<T>): T[] {
2✔
15
  const segments: T[][] = [];
36✔
16

17
  let sameStart = 0;
36✔
18

19
  for (let i = 0; i < patch.length; ++i) {
36✔
20
    const patchItem = patch[i];
72✔
21
    if (sameStart !== patchItem.oldPos) {
72✔
22
      segments.push(a.slice(sameStart, patchItem.oldPos));
36✔
23
    }
24
    if (patchItem.type === 'add') {
72✔
25
      segments.push(patchItem.items);
32✔
26
      sameStart = patchItem.oldPos;
32✔
27
    } else if ((<patch.PatchItem<T>>patchItem).items) {
40✔
28
      sameStart = patchItem.oldPos + (<patch.PatchItem<T>>patchItem).items.length;
21✔
29
    } else {
30
      sameStart = patchItem.oldPos + (<{ length: number }>patchItem).length;
19✔
31
    }
32
  }
33
  if (sameStart !== a.length) {
36✔
34
    segments.push(a.slice(sameStart));
12✔
35
  }
36

37
  return ([] as T[]).concat(...segments);
36✔
38
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc