generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
293e214
commit 711dbe4
Showing
6 changed files
with
128 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
projects/kit/src/lib/utils/find-common-beginning-substr.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export function findCommonBeginningSubstr(a: string, b: string): string { | ||
let res = ''; | ||
|
||
for (let i = 0; i < a.length; i++) { | ||
if (a[i] !== b[i]) { | ||
return res; | ||
} | ||
|
||
res += a[i]; | ||
} | ||
|
||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
projects/kit/src/lib/utils/tests/find-common-beginning-substr.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {findCommonBeginningSubstr} from '../find-common-beginning-substr'; | ||
|
||
describe('findCommonBeginningSubstr', () => { | ||
it('returns common substring until all characters are equal', () => { | ||
expect(findCommonBeginningSubstr('123_456', '123456')).toBe('123'); | ||
}); | ||
|
||
it('returns empty string if any string is empty', () => { | ||
expect(findCommonBeginningSubstr('123_456', '')).toBe(''); | ||
expect(findCommonBeginningSubstr('', '123_456')).toBe(''); | ||
}); | ||
|
||
it('returns empty string if the first characters are different', () => { | ||
expect(findCommonBeginningSubstr('012345', '123')).toBe(''); | ||
}); | ||
|
||
it('returns the whole string if all characters are equal', () => { | ||
expect(findCommonBeginningSubstr('777999', '777999')).toBe('777999'); | ||
}); | ||
}); |