Skip to content

Commit ae3981c

Browse files
heschhenri.schmidt
andauthored
fix: fix splitCommonDiff function to work correctly on common digits after first difference (#1543)
Co-authored-by: henri.schmidt <henri.schmidt@zdf.jp>
1 parent f014612 commit ae3981c

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/numbers/segment.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ describe('Numbers', () => {
125125
12
126126
])
127127
})
128+
129+
it('should work correctly, if there are common digits after first difference', () => {
130+
expect(
131+
splitCommonDiff([1, 0, 3], [1, 2, 3])
132+
).toEqual(['1', 3, 23])
133+
134+
expect(
135+
splitCommonDiff([1, 2, 5, 2], [1, 4, 5, 3])
136+
).toEqual(['1', 252, 453])
137+
})
128138
})
129139

130140
describe('segmentToNumberPatterns', () => {

src/numbers/segment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function splitCommonDiff(a: number[], b: number[]): [string, number, numb
100100
currA = a[i]
101101
currB = b[i]
102102

103-
if (currA === currB) {
103+
if (currA === currB && diffA === '' && diffB === '') {
104104
common += currA
105105
} else {
106106
diffA += currA

0 commit comments

Comments
 (0)