Skip to content

Commit 79b0d27

Browse files
Wayleom Vargas RubioWayleom Vargas Rubio
authored andcommitted
Changed name of stretch assigment file and put it in folder
1 parent 28493cc commit 79b0d27

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export function isValidAlphaAbbreviation(word: string, abbr: string): boolean {
2+
if (word.length < 1 || word.length > 25) return false;
3+
if (abbr.length < 1 || abbr.length > 15) return false;
4+
if (!/^[a-z]+$/.test(word)) return false;
5+
if (!/^[a-z]+$/.test(abbr)) return false;
6+
7+
let wordIndex = 0;
8+
let i = 0;
9+
10+
while (i < abbr.length && wordIndex < word.length) {
11+
const ch: string = abbr[i];
12+
13+
if (word[wordIndex] === ch) {
14+
wordIndex++;
15+
i++;
16+
} else {
17+
const skip: number = ch.charCodeAt(0) - 96;
18+
wordIndex += skip;
19+
i++;
20+
}
21+
}
22+
23+
return wordIndex === word.length && i === abbr.length;
24+
}

0 commit comments

Comments
 (0)