Skip to content

Commit ad141ef

Browse files
feat: removed bang, checked if idx is undefined
1 parent 1c59949 commit ad141ef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lesson_13/maps_ts/src/lesson13.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export function findPermutationDifference(s: string, t: string): number {
1111

1212
let difference = 0;
1313
for (let i = 0; i < s.length; i++) {
14-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15-
difference += Math.abs(i - map.get(s[i])!);
14+
const idx = map.get(s[i]);
15+
if (idx != undefined) {
16+
difference += Math.abs(i - idx);
17+
}
1618
}
1719

1820
return difference;

0 commit comments

Comments
 (0)