Skip to content

Commit 86d6a12

Browse files
author
AmiyahJo
committed
fix: typescript if statement
avoids ts complaining about whether indexInS is undefined
1 parent c09a350 commit 86d6a12

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lesson_13/maps_ts/src/lesson13.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export function findPermutationDifference(s: string, t: string): number {
1717
//Calculate the absolute difference between the index in s and the current index in t.
1818
let indexInS = charPositionMap.get(t.charAt(tIndex));
1919
//Add the absolute difference you calculated to the total difference.
20-
totalDifference += Math.abs(indexInS - tIndex);
20+
if (indexInS != undefined) {
21+
totalDifference += Math.abs(indexInS - tIndex);
22+
}
2123
}
2224
//After going through all characters in t, return the total difference.
2325
return totalDifference;

0 commit comments

Comments
 (0)