Skip to content

Commit 9b6c43a

Browse files
Wayleom Vargas RubioWayleom Vargas Rubio
authored andcommitted
Changed expression calc and stretch assignment
1 parent 60127c1 commit 9b6c43a

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
function isValidAlphaAbbreviation(word: string, abbr: string): boolean {
2-
let wordlength = word.length;
3-
let abbrlength = abbr.length;
42

5-
if (wordlength < abbrlength) return false;
63
if (word.length < 1 || word.length > 25) return false;
74
if (abbr.length < 1 || abbr.length > 15) return false;
85
if (!/^[a-z]+$/.test(word)) return false;
96
if (!/^[a-z]+$/.test(abbr)) return false;
7+
if (abbr.length > word.length) return false;
108

11-
9+
let built = "";
10+
let i = 0;
1211

13-
return true;
14-
}
12+
while (i < word.length) {
13+
const ch = word[i];
14+
15+
built += ch;
16+
i++;
17+
18+
if (i < word.length) {
19+
const skip = ch.charCodeAt(0) - 96;
20+
i += skip;
21+
}
22+
}
23+
24+
return built === abbr;
25+
}
26+
console.log(isValidAlphaAbbreviation("abbreviation", "acefn")); // true
27+
console.log(isValidAlphaAbbreviation("abbreviation", "acehn")); // false
28+
console.log(isValidAlphaAbbreviation("abbreviation", "acgn")); // false
29+
console.log(isValidAlphaAbbreviation("internationalization", "imzdn")); // true
30+
console.log(isValidAlphaAbbreviation("internationalization", "inz")); // false

lesson_06/expression/src/expression_calculator.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@ export class ExpressionCalculator {
33
calculate(a: number, b: number, c: number, d: number, e: number): number {
44
// Implement your code here to return the correct value.
55
// Function to implement: Math.pow((a + b) / c, d) * e
6-
return Math.pow((a + b) / c, d) * e;
6+
return this.multiply(this.pow(this.divide(this.add(a, b), c), d), e);
77
}
88

99
pow(base: number, exponent: number): number {
1010
return Math.pow(base, exponent);
1111
}
12+
add(a: number, b: number): number {
13+
return a + b;
14+
}
15+
multiply(a: number, b: number): number {
16+
return a * b;
17+
}
18+
divide(a: number, b: number): number {
19+
return a / b;
20+
}
21+
subtract(a: number, b: number): number {
22+
return a - b;
23+
}
1224
}

0 commit comments

Comments
 (0)