(a: string, b: string)
| 737 | |
| 738 | // Return array of substrings in a longest common subsequence of strings. |
| 739 | const findCommonSubstrings = (a: string, b: string): Array<string> => { |
| 740 | const array: Array<string> = []; |
| 741 | diff( |
| 742 | a.length, |
| 743 | b.length, |
| 744 | (aIndex: number, bIndex: number) => { |
| 745 | assertMin('input aIndex', aIndex, 0); |
| 746 | assertEnd('input aIndex', aIndex, a.length); |
| 747 | assertMin('input bIndex', bIndex, 0); |
| 748 | assertEnd('input bIndex', bIndex, b.length); |
| 749 | return a[aIndex] === b[bIndex]; |
| 750 | }, |
| 751 | (nCommon: number, aCommon: number, bCommon: number) => { |
| 752 | assertMin('output nCommon', nCommon, 1); |
| 753 | assertMin('output aCommon', aCommon, 0); |
| 754 | assertMax('output aCommon + nCommon', aCommon + nCommon, a.length); |
| 755 | assertMin('output bCommon', bCommon, 0); |
| 756 | assertMax('output bCommon + nCommon', bCommon + nCommon, b.length); |
| 757 | assertCommonSubstring(a, b, nCommon, aCommon, bCommon); |
| 758 | array.push(a.slice(aCommon, aCommon + nCommon)); |
| 759 | }, |
| 760 | ); |
| 761 | return array; |
| 762 | }; |
| 763 | |
| 764 | describe('common substrings', () => { |
| 765 | // Find changed and unchanged substrings within adjacent changed lines |
no test coverage detected