* Finds all unique values in lines[start...end], inclusive. This * function is used in preparation for determining the longest common * subsequence. * * @param lines - The array to search * @param start - The starting index (inclusive) * @param end - The ending index (inclusive)
(lines: string[], start: number, end: number)
| 42 | * @returns A map of the unique lines to their index |
| 43 | */ |
| 44 | function findUnique(lines: string[], start: number, end: number) { |
| 45 | const lineMap = new Map<string, {count: number; index: number}>(); |
| 46 | for (let i = start; i <= end; i++) { |
| 47 | const line = lines[i]; |
| 48 | const data = lineMap.get(line); |
| 49 | if (data) { |
| 50 | data.count++; |
| 51 | data.index = i; |
| 52 | } else { |
| 53 | lineMap.set(line, {count: 1, index: i}); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | const newMap = new Map<string, number>(); |
| 58 | for (const [key, value] of lineMap) { |
| 59 | if (value.count === 1) { |
| 60 | newMap.set(key, value.index); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return newMap; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Finds all the unique common entries between aArray[aStart...aEnd] and |
no test coverage detected