From 54d548d23824644de841b123e7386511610abe04 Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 12:20:56 +0000 Subject: [PATCH 1/3] 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 b99782b298a96106df869d378c3a9976a0ae5cfc Mon Sep 17 00:00:00 2001 From: nilejack Date: Tue, 15 Oct 2024 12:58:38 +0000 Subject: [PATCH 2/3] Feat: Adds/NileJack09-hw --- .../dataprovider/NileJackProvider.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java new file mode 100644 index 000000000..437665660 --- /dev/null +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java @@ -0,0 +1,22 @@ +package com.codedifferently.lesson9.dataprovider; + +import java.util.Map; +import org.springframework.stereotype.Service; + +@Service +public class AnthonyMaysProvider extends DataProvider { + public String getProviderName() { + return "anthonymays"; + } + + public Map getColumnTypeByName() { + return Map.of( + "column1", Integer.class, + "column2", String.class, + "column3", Boolean.class, + "column4", Float.class, + "column5", Double.class, + "column6", Long.class, + "column7", Short.class); + } +} From e1d58d5cacda176004b6ba67c77bea83d79d9342 Mon Sep 17 00:00:00 2001 From: Nile Jackson Date: Tue, 15 Oct 2024 09:03:43 -0400 Subject: [PATCH 3/3] Delete lesson_07/conditionals/src/lesson7.ts Unnecessary file --- lesson_07/conditionals/src/lesson7.ts | 177 -------------------------- 1 file changed, 177 deletions(-) delete mode 100644 lesson_07/conditionals/src/lesson7.ts diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts deleted file mode 100644 index 977fe04a7..000000000 --- a/lesson_07/conditionals/src/lesson7.ts +++ /dev/null @@ -1,177 +0,0 @@ -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. - * - * @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. - */ -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; - } - -} - //This is just an idea(That's probably wrong)/ - // TODO(you): Finish this method. - -} - -/** - * Converts a GPA on the 4.0 scale to the corresponding letter grade using the college board - * scale. See - * https://bigfuture.collegeboard.org/plan-for-college/college-basics/how-to-convert-gpa-4.0-scale - * for details. - * - * @param gpa The GPA value. - * @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"; -} - -} - -/** - * Computes the factorial of the given value of `n`. - * - * @param n The value for which to compute the factorial. - * @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; - } - - return product; -} - -/** - * Adds all of the provided values and returns the sum. - * - * @param values The values to sum. - * @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; -} - -/** - * Returns an array of the first `n` Fibonacci numbers starting from 1. - * - * @param n The first `n` of Fibonacci values to compute. - * @return An array containing the first `n` Fibonacci values. - */ -export function getFirstNFibonacciNumbers(n: number): number[] { - 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 -} - -/** - * Finds a value in an array of values. - * - * @param values The values to search. - * @param start The left most index to search. - * @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. - */ -export function binarySearch( - values: number[], - start: number, - end: number, - 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)); - - } - // TODO(you): Finish implementing this algorithm - - // If values[pivotIndex] is equal to value then return `pivotIndex`. - // 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; -}