From 54d548d23824644de841b123e7386511610abe04 Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 12:20:56 +0000 Subject: [PATCH 1/6] 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 8209f6531a0e58a652feda01cc2ecd709a7573c5 Mon Sep 17 00:00:00 2001 From: nilejack Date: Tue, 15 Oct 2024 15:56:01 +0000 Subject: [PATCH 2/6] feat: completedLesson09/HW --- .../dataprovider/nileJackProvider.java | 26 ++++++ .../src/main/resources/data/nilejack.json | 92 +++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/nileJackProvider.java create mode 100644 lesson_09/types/types_app/src/main/resources/data/nilejack.json 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..4a838c6d5 --- /dev/null +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/nileJackProvider.java @@ -0,0 +1,26 @@ +package com.codedifferently.lesson9.dataprovider; + +import java.util.Map; + +import org.springframework.stereotype.Service; + +@Service +public class nileJackProvider extends DataProvider { + @Override + public String getProviderName() { + return "nilejack"; + } + + @SuppressWarnings("rawtypes") + @Override + public Map getColumnTypeByName() { + return Map.of( + "column1", Long.class, + "column2", Double.class, + "column3", Integer.class, + "column4", Float.class, + "column5", Short.class, + "column6", Boolean.class, + "column7", String.class); + } +} diff --git a/lesson_09/types/types_app/src/main/resources/data/nilejack.json b/lesson_09/types/types_app/src/main/resources/data/nilejack.json new file mode 100644 index 000000000..fd933d308 --- /dev/null +++ b/lesson_09/types/types_app/src/main/resources/data/nilejack.json @@ -0,0 +1,92 @@ +[ + { + "column1": "5650212345839424512", + "column2": "1.0419860471536895E308", + "column3": "532722626", + "column4": "2.2568547E38", + "column5": "13124", + "column6": "false", + "column7": "m5jds0vh" + }, + { + "column1": "3698559821289318400", + "column2": "1.360456713881831E308", + "column3": "344943055", + "column4": "7.4292983E36", + "column5": "25752", + "column6": "true", + "column7": "62wr5hmdj9" + }, + { + "column1": "1207039756574645248", + "column2": "7.982997938103749E307", + "column3": "986203842", + "column4": "1.0375882E37", + "column5": "23969", + "column6": "true", + "column7": "yhf85g" + }, + { + "column1": "5925337373162785792", + "column2": "3.5110092992928476E307", + "column3": "1008854066", + "column4": "2.9334033E38", + "column5": "7434", + "column6": "false", + "column7": "cdyzex792b5" + }, + { + "column1": "553307573053938112", + "column2": "8.846860211577619E307", + "column3": "1007248115", + "column4": "7.5503293E37", + "column5": "15105", + "column6": "true", + "column7": "2klwy69" + }, + { + "column1": "4806196856428403712", + "column2": "1.4537650624894448E308", + "column3": "1313462103", + "column4": "1.0921215E38", + "column5": "10962", + "column6": "false", + "column7": "a1yl9twz0mxj" + }, + { + "column1": "4851563812257616896", + "column2": "2.971416095809706E307", + "column3": "1268963879", + "column4": "7.168383E37", + "column5": "22554", + "column6": "false", + "column7": "af4hngr186q" + }, + { + "column1": "3408733698499404288", + "column2": "8.868182267244585E307", + "column3": "1757054163", + "column4": "2.8916998E38", + "column5": "1936", + "column6": "false", + "column7": "zaq5o2" + }, + { + "column1": "8208429512888680448", + "column2": "1.6017910791400884E308", + "column3": "1669978303", + "column4": "2.2193372E38", + "column5": "10634", + "column6": "true", + "column7": "3z2w6" + }, + { + "column1": "6435911613431203840", + "column2": "9.879109893246474E307", + "column3": "802918450", + "column4": "3.1588135E38", + "column5": "30482", + "column6": "true", + "column7": "hvzfub324mc" + } +] \ No newline at end of file From bdf9599ddfabb6bafd80fef4db66b207d0f85067 Mon Sep 17 00:00:00 2001 From: nilejack Date: Tue, 15 Oct 2024 16:14:58 +0000 Subject: [PATCH 3/6] feat: adds/NileJack/Lesson_09HW --- .../dataprovider/NileJackProvider2.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider2.java diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider2.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider2.java new file mode 100644 index 000000000..c91568630 --- /dev/null +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider2.java @@ -0,0 +1,25 @@ +package com.codedifferently.lesson9.dataprovider; + +import java.util.Map; +import org.springframework.stereotype.Service; + +@Service +public class NileJackProvider2 extends DataProvider { + @Override + public String getProviderName() { + return "nilejack"; + } + + @SuppressWarnings("rawtypes") + @Override + public Map getColumnTypeByName() { + return Map.of( + "column1", Double.class, + "column2", String.class, + "column3", Short.class, + "column4", Integer.class, + "column5", Boolean.class, + "column6", Float.class, + "column7", Long.class); + } +} From 06ee2c26091ce187c1366e6e10ab820cde4d8d4b Mon Sep 17 00:00:00 2001 From: nilejack Date: Tue, 15 Oct 2024 16:16:00 +0000 Subject: [PATCH 4/6] "feat:adds/JSON.file" --- .../src/main/resources/data/nilejack.json | 140 +++++++++--------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/lesson_09/types/types_app/src/main/resources/data/nilejack.json b/lesson_09/types/types_app/src/main/resources/data/nilejack.json index fd933d308..13ba87d7c 100644 --- a/lesson_09/types/types_app/src/main/resources/data/nilejack.json +++ b/lesson_09/types/types_app/src/main/resources/data/nilejack.json @@ -1,92 +1,92 @@ [ { - "column1": "5650212345839424512", - "column2": "1.0419860471536895E308", - "column3": "532722626", - "column4": "2.2568547E38", - "column5": "13124", - "column6": "false", - "column7": "m5jds0vh" + "column1": "1.2155415868200682E308", + "column2": "ay7uqf59vgk", + "column3": "13631", + "column4": "392587112", + "column5": "true", + "column6": "2.8648133E38", + "column7": "6297398905888630784" }, { - "column1": "3698559821289318400", - "column2": "1.360456713881831E308", - "column3": "344943055", - "column4": "7.4292983E36", - "column5": "25752", - "column6": "true", - "column7": "62wr5hmdj9" + "column1": "8.321620430752238E307", + "column2": "5yqhp07k6gc", + "column3": "12985", + "column4": "2138528365", + "column5": "true", + "column6": "3.083706E37", + "column7": "2616303035857536512" }, { - "column1": "1207039756574645248", - "column2": "7.982997938103749E307", - "column3": "986203842", - "column4": "1.0375882E37", - "column5": "23969", - "column6": "true", - "column7": "yhf85g" + "column1": "7.314389284316176E307", + "column2": "in3qm8o5f7c2", + "column3": "30361", + "column4": "1874275284", + "column5": "false", + "column6": "2.7549848E38", + "column7": "8536738639975246848" }, { - "column1": "5925337373162785792", - "column2": "3.5110092992928476E307", - "column3": "1008854066", - "column4": "2.9334033E38", - "column5": "7434", - "column6": "false", - "column7": "cdyzex792b5" + "column1": "4.590854083968467E307", + "column2": "453gqy02cns", + "column3": "16147", + "column4": "1478502328", + "column5": "false", + "column6": "1.2205455E38", + "column7": "4986821522086977536" }, { - "column1": "553307573053938112", - "column2": "8.846860211577619E307", - "column3": "1007248115", - "column4": "7.5503293E37", - "column5": "15105", - "column6": "true", - "column7": "2klwy69" + "column1": "5.539101999945017E307", + "column2": "af9yj1mi", + "column3": "1563", + "column4": "1121270896", + "column5": "false", + "column6": "1.7991684E38", + "column7": "8464433726762726400" }, { - "column1": "4806196856428403712", - "column2": "1.4537650624894448E308", - "column3": "1313462103", - "column4": "1.0921215E38", - "column5": "10962", - "column6": "false", - "column7": "a1yl9twz0mxj" + "column1": "1.7336734246153826E308", + "column2": "ewunyjfxqd4", + "column3": "23145", + "column4": "1044014594", + "column5": "false", + "column6": "2.532904E37", + "column7": "6806636668204898304" }, { - "column1": "4851563812257616896", - "column2": "2.971416095809706E307", - "column3": "1268963879", - "column4": "7.168383E37", - "column5": "22554", - "column6": "false", - "column7": "af4hngr186q" + "column1": "1.7645926782579685E308", + "column2": "2xf6pw3ql4", + "column3": "19516", + "column4": "400596822", + "column5": "false", + "column6": "2.32627E38", + "column7": "2038097960985824512" }, { - "column1": "3408733698499404288", - "column2": "8.868182267244585E307", - "column3": "1757054163", - "column4": "2.8916998E38", - "column5": "1936", - "column6": "false", - "column7": "zaq5o2" + "column1": "3.9156902272053513E307", + "column2": "iygew2qvtou", + "column3": "7088", + "column4": "362362593", + "column5": "true", + "column6": "3.2023805E38", + "column7": "5273750678048173056" }, { - "column1": "8208429512888680448", - "column2": "1.6017910791400884E308", - "column3": "1669978303", - "column4": "2.2193372E38", - "column5": "10634", - "column6": "true", - "column7": "3z2w6" + "column1": "1.2284458016333363E308", + "column2": "py3o84c6kqf", + "column3": "27005", + "column4": "1810294689", + "column5": "false", + "column6": "1.5230078E38", + "column7": "8212126872880282624" }, { - "column1": "6435911613431203840", - "column2": "9.879109893246474E307", - "column3": "802918450", - "column4": "3.1588135E38", - "column5": "30482", - "column6": "true", - "column7": "hvzfub324mc" + "column1": "1.439695246182645E308", + "column2": "x7d8ibz09re1", + "column3": "22486", + "column4": "520410192", + "column5": "true", + "column6": "1.0172832E38", + "column7": "4673806278628105216" } ] \ No newline at end of file From 4ea78bea2e17852a5cf2ab69ca8072e1061d4f7e Mon Sep 17 00:00:00 2001 From: Nile Jackson Date: Tue, 15 Oct 2024 12:17:30 -0400 Subject: [PATCH 5/6] Delete lesson_07/conditionals/src/lesson7.ts --- 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; -} From 5969623a6cb457f331f17367acc2c4f4c39d5efe Mon Sep 17 00:00:00 2001 From: nilejack Date: Tue, 15 Oct 2024 20:43:10 +0000 Subject: [PATCH 6/6] Revert "feat:adds lesson_07/conditionals-nilejackson" This reverts commit 54d548d23824644de841b123e7386511610abe04. --- .../dataprovider/nileJackProvider.java | 26 ------------------- 1 file changed, 26 deletions(-) delete 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 deleted file mode 100644 index 4a838c6d5..000000000 --- a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/nileJackProvider.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.codedifferently.lesson9.dataprovider; - -import java.util.Map; - -import org.springframework.stereotype.Service; - -@Service -public class nileJackProvider extends DataProvider { - @Override - public String getProviderName() { - return "nilejack"; - } - - @SuppressWarnings("rawtypes") - @Override - public Map getColumnTypeByName() { - return Map.of( - "column1", Long.class, - "column2", Double.class, - "column3", Integer.class, - "column4", Float.class, - "column5", Short.class, - "column6", Boolean.class, - "column7", String.class); - } -}