Skip to content

Commit

Permalink
fix: fix splitCommonDiff function to work correctly on common digits …
Browse files Browse the repository at this point in the history
…after first difference (#1543)

Co-authored-by: henri.schmidt <henri.schmidt@zdf.jp>
  • Loading branch information
hesch and henri.schmidt committed Apr 5, 2024
1 parent f014612 commit ae3981c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/numbers/segment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ describe('Numbers', () => {
12
])
})

it('should work correctly, if there are common digits after first difference', () => {
expect(
splitCommonDiff([1, 0, 3], [1, 2, 3])
).toEqual(['1', 3, 23])

expect(
splitCommonDiff([1, 2, 5, 2], [1, 4, 5, 3])
).toEqual(['1', 252, 453])
})
})

describe('segmentToNumberPatterns', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/numbers/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function splitCommonDiff(a: number[], b: number[]): [string, number, numb
currA = a[i]
currB = b[i]

if (currA === currB) {
if (currA === currB && diffA === '' && diffB === '') {
common += currA
} else {
diffA += currA
Expand Down

0 comments on commit ae3981c

Please sign in to comment.