From 5bdd13132d2f7a03986be17ef89bb364ed463e32 Mon Sep 17 00:00:00 2001 From: zionbuch Date: Tue, 8 Oct 2024 14:47:17 +0000 Subject: [PATCH 1/4] feat:lesson_06 homework --- lesson_06/expression/src/expression_calculator.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lesson_06/expression/src/expression_calculator.ts b/lesson_06/expression/src/expression_calculator.ts index 13cb2ca05..3f42b898e 100644 --- a/lesson_06/expression/src/expression_calculator.ts +++ b/lesson_06/expression/src/expression_calculator.ts @@ -1,11 +1,24 @@ export class ExpressionCalculator { /** Returns the calculation of ((a + b) * c) / d^e */ calculate(a: number, b: number, c: number, d: number, e: number): number { + const sum = this.add(a, b); + const product = this.mult(sum, c); + const expo = this.pow(d, e); + const result = this.div(product, expo); // Implement your code here to return the correct value. - return 0; + return this.div(product, expo); } pow(base: number, exponent: number): number { return Math.pow(base, exponent); } + add(num1: number, num2: number): number { + return num1 + num2; + } + mult(num1: number, num2: number): number { + return num1 * num2; + } + div(num1: number, num2: number): number { + return num1 / num2; + } } From 408e56349668835dc3a6b6901a6da561bd6be712 Mon Sep 17 00:00:00 2001 From: zionbuch Date: Wed, 9 Oct 2024 14:03:47 +0000 Subject: [PATCH 2/4] made changes to my result variable --- lesson_06/expression/src/expression_calculator.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lesson_06/expression/src/expression_calculator.ts b/lesson_06/expression/src/expression_calculator.ts index 3f42b898e..042677650 100644 --- a/lesson_06/expression/src/expression_calculator.ts +++ b/lesson_06/expression/src/expression_calculator.ts @@ -4,7 +4,6 @@ export class ExpressionCalculator { const sum = this.add(a, b); const product = this.mult(sum, c); const expo = this.pow(d, e); - const result = this.div(product, expo); // Implement your code here to return the correct value. return this.div(product, expo); } From 51c8d93633cffe891ee9a3ad43869bc2df038d63 Mon Sep 17 00:00:00 2001 From: zionbuch Date: Fri, 11 Oct 2024 15:53:15 +0000 Subject: [PATCH 3/4] working on lesson_07 --- lesson_07/conditionals/src/lesson7.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index 52f45df8b..816f8db62 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -7,6 +7,9 @@ import { computeLexicographicDistance } from "./util.js"; * @return True if the age corresponds to a voting age and false otherwise. */ export function canVote(age: number): boolean { + if (age >= 18) { + return true; + } return false; } @@ -18,10 +21,19 @@ export function canVote(age: number): boolean { * @return -1 if a is less than b, 1 if a is greater than b, and 0 otherwise. */ export function compareStrings(a: string, b: string): number { + if (a > b) { + return 1; + } + if (a < b) { + return -1; + } + if (a=b) { + return 0; + } // The distance will be a number less than 0 if string `a` is lexicographically less than `b`, 1 // if it is greater, and 0 if the strings are equal. const distance = computeLexicographicDistance(a, b); - + // TODO(you): Finish this method. return 0; @@ -47,6 +59,8 @@ export function convertGpaToLetterGrade(gpa: number): string { * @return The factorial of n. */ export function computeFactorial(n: number): number { + let product=1 + for() return 0; } From b2a1d9f9a7d4263d93727f35588a5310661b6ba9 Mon Sep 17 00:00:00 2001 From: zionbuch Date: Mon, 14 Oct 2024 13:53:03 +0000 Subject: [PATCH 4/4] feat:adding lesson07 homework --- lesson_07/conditionals/src/lesson7.ts | 85 +++++++++++++++++++++------ 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index 816f8db62..d626f0612 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -18,25 +18,22 @@ export function canVote(age: number): boolean { * * @param a The first `string` to compare. * @param b The second `string` to compare. - * @return -1 if a is less than b, 1 if a is greater than b, and 0 otherwise. + * @return -1 if a (the first 'string) is less than b (the second 'string'), 1 if a is greater than b, and 0 otherwise. */ export function compareStrings(a: string, b: string): number { - if (a > b) { + // The distance will be a number less than 0 if string `a` is lexicographically less than `b`, + // 1 if it is greater b, and 0 if both strings are equal. + const distance = computeLexicographicDistance(a, b); + + if (distance < 0) { + return -1; + } else if (distance > 0) { return 1; - } - if (a < b) { - return -1; - } - if (a=b) { + } else { return 0; } - // The distance will be a number less than 0 if string `a` is lexicographically less than `b`, 1 - // if it is greater, and 0 if the strings are equal. - const distance = computeLexicographicDistance(a, b); - - // TODO(you): Finish this method. - return 0; + // TODO(you): Finish this method. } /** @@ -49,7 +46,31 @@ export function compareStrings(a: string, b: string): number { * @return The letter grade ("A+", "A", "A-", "B+", etc.). */ export function convertGpaToLetterGrade(gpa: number): string { - return "F"; + if (gpa === 4.0) { + return "A"; + } else if (gpa > 4.0) { + return "A"; + } else if (gpa <= 3.99 && gpa >= 3.7) { + return "A-"; + } else if (gpa <= 3.69 && gpa >= 3.3) { + return "B+"; + } else if (gpa <= 3.29 && gpa >= 3.0) { + return "B"; + } else if (gpa <= 2.99 && gpa >= 2.7) { + return "B-"; + } else if (gpa <= 2.69 && gpa >= 2.3) { + return "C+"; + } else if (gpa <= 2.29 && gpa >= 2.0) { + return "C"; + } else if (gpa <= 1.99 && gpa >= 1.7) { + return "C-"; + } else if (gpa <= 1.69 && gpa >= 1.3) { + return "D+"; + } else if (gpa <= 1.29 && gpa >= 1.0) { + return "D"; + } else { + return "F"; + } } /** @@ -59,9 +80,12 @@ export function convertGpaToLetterGrade(gpa: number): string { * @return The factorial of n. */ export function computeFactorial(n: number): number { - let product=1 - for() - return 0; + let product = 1; + for (let i = 1; 1 <= n; i++) { + product *= i; + } + + return product; } /** @@ -71,7 +95,11 @@ export function computeFactorial(n: number): number { * @return The sum of all the values. */ export function addNumbers(values: number[]): number { - return 0; + let sum = 0; + for (const value of values) { + sum += value; + } + return sum; } /** @@ -81,7 +109,18 @@ export function addNumbers(values: number[]): number { * @return An array containing the first `n` Fibonacci values. */ export function getFirstNFibonacciNumbers(n: number): number[] { - return []; + let current = 1; + let prev = 0; + + const numbers = []; + for (let i = 1; i <= n; i++) { + numbers.push(current); + const nextNum = current + prev; + prev = current; + current = nextNum; + } + + return numbers; } /** @@ -105,6 +144,13 @@ export function binarySearch( } const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array. + if (values[pivotIndex] === value) { + return pivotIndex; + } else if (values[pivotIndex] > value) { + return binarySearch(values, start, pivotIndex - 1, value); + } else { + return binarySearch(values, pivotIndex + 1, end, value); + } // TODO(you): Finish implementing this algorithm @@ -112,5 +158,6 @@ export function binarySearch( // Else if values[pivotIndex] is greater than the value, then // call `binarySearch(values, start, pivotIndex - 1, value)` and return its value; // Else call `binarySearch(values, pivotIndex + 1, end, value)` and return its value. + return -1; }