Skip to content

Commit 59fb845

Browse files
committed
refactor(regionMatchers): rm magic numbers
1 parent cbfe4ec commit 59fb845

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/regionMatchers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ interface StringRegion {
3333
* regionMatch(str5, str6); // true
3434
*/
3535
function regionMatch(str1: StringRegion | string, str2: StringRegion | string, start?: number, end?: number): boolean {
36+
const ZERO_IDX = 0
3637
// Normalizing Inputs
3738
// Strings to StringRegion
3839
if (typeof str1 === 'string' || typeof str2 === 'string') {
39-
start = start ?? 0
40+
start ??= ZERO_IDX
4041
if (typeof str1 === 'string') {
4142
const e = end ?? str1.length
4243
str1 = { str: str1, start, end: e }
@@ -48,10 +49,10 @@ function regionMatch(str1: StringRegion | string, str2: StringRegion | string, s
4849
}
4950

5051
// Getting start and end for both strings
51-
const s1 = str1.start ?? 0
52+
const s1 = str1.start ?? ZERO_IDX
5253
const e1 = str1.end ?? str1.str.length
5354

54-
const s2 = str2.start ?? 0
55+
const s2 = str2.start ?? ZERO_IDX
5556
const e2 = str2.end ?? str2.str.length
5657

5758
return str1.str.substring(s1, e1) === str2.str.substring(s2, e2)

0 commit comments

Comments
 (0)