We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 28493cc commit 79b0d27Copy full SHA for 79b0d27
lesson_06/expression/src/wayleomvargas/abbreviation-validator.ts
@@ -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
20
+ }
21
22
23
+ return wordIndex === word.length && i === abbr.length;
24
+}
0 commit comments