From d5ecf4f25f77c76f00362fca9240d35dc4bf7d56 Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 12:20:56 +0000 Subject: [PATCH 1/9] feat:adds lesson_07/conditionals-nilejackson --- lesson_07/conditionals/src/lesson7.ts | 91 ++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index 52f45df8b..977fe04a7 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -1,15 +1,22 @@ import { computeLexicographicDistance } from "./util.js"; -/** +/** * Returns true if the provided age meets the minimum US voting age and false otherwise. * * @param age The age to check. * @return True if the age corresponds to a voting age and false otherwise. - */ + */ + export function canVote(age: number): boolean { + return false; +if(age >= 18) { + return true; +} else { return false; -} +} +console.log(age >= 18); +} /** * Compares two strings lexicographically. * @@ -20,11 +27,21 @@ export function canVote(age: number): boolean { 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); + const distance = computeLexicographicDistance(a, b); + distance; a; 1; + distance; b; 1; { + if(distance > 0) { + return 1; //equal distances + } else if(distance <0 ) { + return -1; //unequal distances + } else if(distance === 0) { + return 0; + } +} + //This is just an idea(That's probably wrong)/ // TODO(you): Finish this method. - - return 0; + } /** @@ -38,6 +55,30 @@ export function compareStrings(a: string, b: string): number { */ export function convertGpaToLetterGrade(gpa: number): string { return "F"; +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"; +} + } /** @@ -48,6 +89,12 @@ export function convertGpaToLetterGrade(gpa: number): string { */ export function computeFactorial(n: number): number { return 0; + let product = 1; + for (let i = 1; 1 <= n; i++) { + product *= i; + } + + return product; } /** @@ -58,6 +105,10 @@ export function computeFactorial(n: number): number { */ export function addNumbers(values: number[]): number { return 0; + let sum = 0; for(const value of values) { + sum + value; + } + return sum; } /** @@ -67,7 +118,17 @@ export function addNumbers(values: number[]): number { * @return An array containing the first `n` Fibonacci values. */ export function getFirstNFibonacciNumbers(n: number): number[] { - return []; + if (n < 1) { + return []; + } + + const fibonacci: number[] = [1, 1]; // The function starts with the first two Fibonacci numbers + + for (let i = 2; i < n; i++) { + fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2]; // Here the sum of the preceeding expression(?) is iterated with the number directly preceeding it + } + + return fibonacci.slice(0, n); // Return only the first n Fibonacci numbers } /** @@ -86,12 +147,26 @@ export function binarySearch( value: number, ): number { if (end < start) { - // The range is not valid so just return -1. + return -1; } + + + + 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); + return value; + } else { + return (binarySearch(values, pivotIndex +1, end, value)); + + } // TODO(you): Finish implementing this algorithm // If values[pivotIndex] is equal to value then return `pivotIndex`. From 75fedc8331ac4e692821a543ec2ea27b419c8ee1 Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 12:58:54 +0000 Subject: [PATCH 2/9] feat:adds-nilejack/hw --- lesson_07/conditionals/src/lesson7.ts | 111 +++++++++++--------------- 1 file changed, 47 insertions(+), 64 deletions(-) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index 977fe04a7..ddc91f1e8 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -1,21 +1,18 @@ import { computeLexicographicDistance } from "./util.js"; -/** +/** * Returns true if the provided age meets the minimum US voting age and false otherwise. * * @param age The age to check. * @return True if the age corresponds to a voting age and false otherwise. - */ + */ export function canVote(age: number): boolean { - return false; -if(age >= 18) { - return true; -} else { - return false; -} -console.log(age >= 18); - + if (age >= 18) { + return true; + } else { + return false; + } } /** * Compares two strings lexicographically. @@ -27,21 +24,17 @@ console.log(age >= 18); 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); - distance; a; 1; - distance; b; 1; { - if(distance > 0) { - return 1; //equal distances - } else if(distance <0 ) { - return -1; //unequal distances - } else if(distance === 0) { - return 0; - } + const distance = computeLexicographicDistance(a, b); -} //This is just an idea(That's probably wrong)/ // TODO(you): Finish this method. - + let stringLengthCompare = 0; + if (distance > 0) { + stringLengthCompare = 1; //equal distances + } else if (distance < 0) { + stringLengthCompare = -1; //unequal distances + } + return stringLengthCompare; } /** @@ -54,31 +47,29 @@ 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 <= 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"; -} - + 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"; + } } /** @@ -88,7 +79,6 @@ if (gpa == 4.0) { * @return The factorial of n. */ export function computeFactorial(n: number): number { - return 0; let product = 1; for (let i = 1; 1 <= n; i++) { product *= i; @@ -104,9 +94,9 @@ 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; + let sum = 0; + for (const value of values) { + sum += value; } return sum; } @@ -125,7 +115,7 @@ export function getFirstNFibonacciNumbers(n: number): number[] { const fibonacci: number[] = [1, 1]; // The function starts with the first two Fibonacci numbers for (let i = 2; i < n; i++) { - fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2]; // Here the sum of the preceeding expression(?) is iterated with the number directly preceeding it + fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2]; // Here the sum of the preceeding expression(?) is iterated with the number directly preceeding it } return fibonacci.slice(0, n); // Return only the first n Fibonacci numbers @@ -147,26 +137,19 @@ export function binarySearch( value: number, ): number { if (end < start) { - return -1; } - - - - 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); - return value; - } else { - return (binarySearch(values, pivotIndex +1, end, value)); - - } + return binarySearch(values, start, pivotIndex - 1, value); + return value; + } else { + return binarySearch(values, pivotIndex + 1, end, value); + } // TODO(you): Finish implementing this algorithm // If values[pivotIndex] is equal to value then return `pivotIndex`. From 96e5125285a555c23c6356dd1f8aba8312cbe761 Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 12:59:45 +0000 Subject: [PATCH 3/9] feat:adds-nileJack/hw --- lesson_07/conditionals/package-lock.json | 8 ++++---- lesson_07/conditionals/package.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lesson_07/conditionals/package-lock.json b/lesson_07/conditionals/package-lock.json index 6c2e02652..b91951020 100644 --- a/lesson_07/conditionals/package-lock.json +++ b/lesson_07/conditionals/package-lock.json @@ -21,7 +21,7 @@ "prettier": "3.3.3", "ts-jest": "^29.2.5", "ts-node": "^10.9.2", - "typescript": "^5.6.2", + "typescript": "^5.6.3", "typescript-eslint": "^8.7.0" } }, @@ -5335,9 +5335,9 @@ } }, "node_modules/typescript": { - "version": "5.6.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", - "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", + "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/lesson_07/conditionals/package.json b/lesson_07/conditionals/package.json index 6e09f98e0..1298e73da 100644 --- a/lesson_07/conditionals/package.json +++ b/lesson_07/conditionals/package.json @@ -28,7 +28,7 @@ "prettier": "3.3.3", "ts-jest": "^29.2.5", "ts-node": "^10.9.2", - "typescript": "^5.6.2", + "typescript": "^5.6.3", "typescript-eslint": "^8.7.0" } -} \ No newline at end of file +} From a16b1b3b9c4ebf71fde9d1f7ccca6be1c12b32ba Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 13:21:50 +0000 Subject: [PATCH 4/9] feat: adds lesson_07/nileajck-hw --- 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 ddc91f1e8..0accab8ec 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -67,7 +67,7 @@ export function convertGpaToLetterGrade(gpa: number): string { return "D+"; } else if (gpa <= 1.29 && gpa >= 1.0) { return "D"; - } else { + } else if (gpa < 1.00 && gpa { return "F"; } } From 69cc4027b60e52780349ab39ba4d4ab6bb0e493b Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 14:54:11 +0000 Subject: [PATCH 5/9] feat: adds nilejack/07Hw --- lesson_07/conditionals/src/lesson7.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index 0accab8ec..7049314b3 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -67,9 +67,7 @@ export function convertGpaToLetterGrade(gpa: number): string { return "D+"; } else if (gpa <= 1.29 && gpa >= 1.0) { return "D"; - } else if (gpa < 1.00 && gpa { - return "F"; - } + } else return "F"; } /** From d27060c629ba1c2e0b2b7f9eabc8c432ee60d78c Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 15:55:21 +0000 Subject: [PATCH 6/9] Feat: fixFor/nilejackLesson07/Hw --- lesson_07/conditionals/src/lesson7.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index 7049314b3..80a7b419f 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -47,7 +47,7 @@ export function compareStrings(a: string, b: string): number { * @return The letter grade ("A+", "A", "A-", "B+", etc.). */ export function convertGpaToLetterGrade(gpa: number): string { - if (gpa == 4.0) { + if (gpa >= 4.0) { return "A"; } else if (gpa <= 3.99 && gpa >= 3.7) { return "A-"; @@ -107,7 +107,7 @@ export function addNumbers(values: number[]): number { */ export function getFirstNFibonacciNumbers(n: number): number[] { if (n < 1) { - return []; + //return []; } const fibonacci: number[] = [1, 1]; // The function starts with the first two Fibonacci numbers From a43eac49b3b581456897247c6f3d06a3853f2bf0 Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 18:38:36 +0000 Subject: [PATCH 7/9] fixed infinite iteration --- 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 80a7b419f..888026f32 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -123,7 +123,7 @@ export function getFirstNFibonacciNumbers(n: number): number[] { * Finds a value in an array of values. * * @param values The values to search. - * @param start The left most index to search. + * @param start The left most index to search.e * @param end The right most index to search. * @param value The value to look for. * @return The index of the value if found in the array and -1 otherwise. From 194e485cadbf9b6cbbadba4c10d94001fef44cd6 Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 18:47:18 +0000 Subject: [PATCH 8/9] feats: fixed iteration --- lesson_07/conditionals/src/lesson7.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index 888026f32..96e48005c 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -84,7 +84,9 @@ export function computeFactorial(n: number): number { return product; } +const n = 2; +console.log(computeFactorial(n)); /** * Adds all of the provided values and returns the sum. * From 1824990c1aee76f2d9b8f770e88782f472f42602 Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 20:57:53 +0000 Subject: [PATCH 9/9] feat: fix/lesson_07-nilejack --- 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 96e48005c..32bb67393 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -78,7 +78,7 @@ export function convertGpaToLetterGrade(gpa: number): string { */ export function computeFactorial(n: number): number { let product = 1; - for (let i = 1; 1 <= n; i++) { + for (let i = 1; i <= n; i++) { product *= i; }