From 089c75ecc332bb2ae96a0d5235dd739e1d8ce31e Mon Sep 17 00:00:00 2001 From: karensprojects22 Date: Thu, 20 Mar 2025 19:32:47 +0000 Subject: [PATCH 1/5] feat: adds Karens lesson_07 --- lesson_07/conditionals/src/lesson7.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index cc44be44c..5c821fe15 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -11,9 +11,15 @@ export function compareStrings(a: string, b: string): number { // 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. - + if (distance < 0){ + return -1; + } + if (distance > 0) { + return 1; + } + if (distance === 0) { + return 1; + } return 0; } From e3b64ad3a5b6c3e0e79cfde5eabcc8900f7301d7 Mon Sep 17 00:00:00 2001 From: karensprojects22 Date: Fri, 21 Mar 2025 15:31:39 +0000 Subject: [PATCH 2/5] feat: adds Karens lesson_07.ts --- lesson_07/conditionals/.env.test | 2 +- lesson_07/conditionals/src/lesson7.ts | 34 ++++++++++++++++++++------- lesson_07/conditionals/src/part_d.ts | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lesson_07/conditionals/.env.test b/lesson_07/conditionals/.env.test index de8c44249..f811b9059 100644 --- a/lesson_07/conditionals/.env.test +++ b/lesson_07/conditionals/.env.test @@ -1 +1 @@ -HW_VERSION=your homework version here \ No newline at end of file +HW_VERSION=D \ No newline at end of file diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index 5c821fe15..b315c4c70 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -11,16 +11,13 @@ export function compareStrings(a: string, b: string): number { // 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); - if (distance < 0){ + if (distance < 0) { return -1; - } - if (distance > 0) { - return 1; - } - if (distance === 0) { + } else if (distance > 0) { return 1; + } else { + return 0; } - return 0; } /** @@ -40,7 +37,20 @@ export function computeFactorial(n: number): number { * @return An array containing the first `n` Fibonacci values. */ export function getFirstNFibonacciNumbers(n: number): number[] { - return []; + /* fibionacci formula - f(n) = f(n-1) + f(n-2)... */ + if (n === 0) { + return []; + } + if (n === 1) { + return [1]; + } + // create array + const number: number[] = [1, 1]; + for (let i = 2; i < n; i++) { + //iterate thorugh items in array + number.push(number[i - 1] + number[i - 2]); + } + return number; } /** @@ -71,5 +81,11 @@ 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; + 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); + } } diff --git a/lesson_07/conditionals/src/part_d.ts b/lesson_07/conditionals/src/part_d.ts index c30cbac2f..2b40e08f4 100644 --- a/lesson_07/conditionals/src/part_d.ts +++ b/lesson_07/conditionals/src/part_d.ts @@ -7,7 +7,7 @@ * @returns */ export function isWithinRange(num: number, min: number, max: number): boolean { - return false; + } /** From dd29d2fb163f6cdc0b1605d2f4fd31576f0da35d Mon Sep 17 00:00:00 2001 From: karensprojects22 Date: Fri, 21 Mar 2025 16:49:57 +0000 Subject: [PATCH 3/5] feat: adds Karens lesson_07 part_d completed problems --- lesson_07/conditionals/src/part_d.ts | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/lesson_07/conditionals/src/part_d.ts b/lesson_07/conditionals/src/part_d.ts index 2b40e08f4..df0cb88ed 100644 --- a/lesson_07/conditionals/src/part_d.ts +++ b/lesson_07/conditionals/src/part_d.ts @@ -7,7 +7,11 @@ * @returns */ export function isWithinRange(num: number, min: number, max: number): boolean { - + if (num >= min && num <= max) { + return true; + } else { + return false; + } } /** @@ -19,7 +23,14 @@ export function isWithinRange(num: number, min: number, max: number): boolean { * @returns */ export function isValidTriangle(a: number, b: number, c: number): boolean { - return false; + /* a + b > c + a + c > b + b + c > a*/ + if (a + b > c && a + c > b && b + c > a) { + return true; + } else { + return false; + } } /** @@ -30,5 +41,18 @@ export function isValidTriangle(a: number, b: number, c: number): boolean { * @returns */ export function getSeason(month: number): string { - return "Invalid month"; + if (month === 1 || month === 2 || month === 12) { + return "Winter"; + } + if (month === 3 || month === 4 || month === 5) { + return "Spring"; + } + if (month === 6 || month === 7 || month === 8) { + return "Summer"; + } + if (month === 9 || month === 10 || month === 11) { + return "Fall"; + } else { + return "Invalid month"; + } } From de354a02c6078fc228c1a7c143ad5c49286df6e5 Mon Sep 17 00:00:00 2001 From: karensprojects22 Date: Sat, 22 Mar 2025 15:44:15 +0000 Subject: [PATCH 4/5] chore:"deleted commented code on Karens lesson_07" --- lesson_07/conditionals/src/lesson7.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index b315c4c70..68d4d6d79 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -37,7 +37,7 @@ export function computeFactorial(n: number): number { * @return An array containing the first `n` Fibonacci values. */ export function getFirstNFibonacciNumbers(n: number): number[] { - /* fibionacci formula - f(n) = f(n-1) + f(n-2)... */ + // edge cases if (n === 0) { return []; } From e3446a16b5d5f55ae6f351ac58287a0b634930cd Mon Sep 17 00:00:00 2001 From: karensprojects22 Date: Wed, 26 Mar 2025 20:20:25 +0000 Subject: [PATCH 5/5] chore: updates Karens lesson_07.ts --- lesson_07/conditionals/src/lesson7.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index 68d4d6d79..12948d106 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -27,7 +27,22 @@ export function compareStrings(a: string, b: string): number { * @return The factorial of n. */ export function computeFactorial(n: number): number { - return 0; + // worked with Davis to complete this coding problem + // edge cases + if (n === 0) { + return 1; + } + if (n === 1) { + return 1; + } + if (n < 0) { + return 0; + } + let result = 1; + for (let i = 2; i <= n; i++) { + result *= i; + } + return result; } /**