diff --git a/lesson_06/expression/.env.test b/lesson_06/expression/.env.test index 56cf4a06f..9fd9f468b 100644 --- a/lesson_06/expression/.env.test +++ b/lesson_06/expression/.env.test @@ -1 +1 @@ -HW_VERSION=your assigned version here \ No newline at end of file +HW_VERSION=E \ No newline at end of file diff --git a/lesson_06/expression/src/expression_calculator.ts b/lesson_06/expression/src/expression_calculator.ts index 76b215c42..9d2e34663 100644 --- a/lesson_06/expression/src/expression_calculator.ts +++ b/lesson_06/expression/src/expression_calculator.ts @@ -2,10 +2,23 @@ export class ExpressionCalculator { /** Returns a calculation involving a, b, c, d, and e */ calculate(a: number, b: number, c: number, d: number, e: number): number { // Implement your code here to return the correct value. - return 0; + // Function to implement: Math.pow((a + b) / c, d) * e + return this.multiply(this.pow(this.divide(this.add(a, b), c), d), e); } pow(base: number, exponent: number): number { return Math.pow(base, exponent); } + add(a: number, b: number): number { + return a + b; + } + multiply(a: number, b: number): number { + return a * b; + } + divide(a: number, b: number): number { + return a / b; + } + subtract(a: number, b: number): number { + return a - b; + } } diff --git a/lesson_06/expression/src/wayleomvargas/abbreviation-validator.ts b/lesson_06/expression/src/wayleomvargas/abbreviation-validator.ts new file mode 100644 index 000000000..047e9ccb7 --- /dev/null +++ b/lesson_06/expression/src/wayleomvargas/abbreviation-validator.ts @@ -0,0 +1,24 @@ +function isValidAlphaAbbreviation(word: string, abbr: string): boolean { + if (word.length < 1 || word.length > 25) return false; + if (abbr.length < 1 || abbr.length > 15) return false; + if (!/^[a-z]+$/.test(word)) return false; + if (!/^[a-z]+$/.test(abbr)) return false; + + let wordIndex = 0; + let i = 0; + + while (i < abbr.length && wordIndex < word.length) { + const ch: string = abbr[i]; + + if (word[wordIndex] === ch) { + wordIndex++; + i++; + } else { + const skip: number = ch.charCodeAt(0) - 96; + wordIndex += skip; + i++; + } + } + + return wordIndex === word.length && i === abbr.length; +} \ No newline at end of file