Skip to content

Amiyah Jones , Feature/lesson 07 : functions, loops, and statements #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8cc92d0
Create README.md
AmiyahJo Sep 24, 2024
50b1861
Delete lesson_00/amiyahjones/README.md
AmiyahJo Sep 24, 2024
27d57c0
Merge branch 'code-differently:main' into main
AmiyahJo Sep 25, 2024
fa3c700
Merge branch 'code-differently:main' into main
AmiyahJo Sep 26, 2024
7c2d053
Merge branch 'code-differently:main' into main
AmiyahJo Sep 26, 2024
faedd1b
Merge branch 'code-differently:main' into main
AmiyahJo Sep 26, 2024
19a4187
Merge branch 'code-differently:main' into main
AmiyahJo Sep 26, 2024
7711266
Merge branch 'code-differently:main' into main
AmiyahJo Sep 27, 2024
9a10c4c
Merge branch 'code-differently:main' into main
AmiyahJo Sep 27, 2024
3ea50c4
Merge branch 'code-differently:main' into main
AmiyahJo Sep 27, 2024
d7b772d
Merge branch 'code-differently:main' into main
AmiyahJo Sep 27, 2024
de46b67
Merge branch 'code-differently:main' into main
AmiyahJo Sep 27, 2024
b891561
Merge branch 'code-differently:main' into main
AmiyahJo Sep 28, 2024
7c9f2db
Merge branch 'code-differently:main' into main
AmiyahJo Sep 30, 2024
ff3ba35
Merge branch 'code-differently:main' into main
AmiyahJo Sep 30, 2024
457feea
Merge branch 'code-differently:main' into main
AmiyahJo Sep 30, 2024
5868f9d
Merge branch 'code-differently:main' into main
AmiyahJo Oct 1, 2024
28eacd4
Merge branch 'code-differently:main' into main
AmiyahJo Oct 1, 2024
bca4933
Merge branch 'code-differently:main' into main
AmiyahJo Oct 1, 2024
9ff0f9e
Merge branch 'code-differently:main' into main
AmiyahJo Oct 1, 2024
8d02849
Merge branch 'code-differently:main' into main
AmiyahJo Oct 2, 2024
6dd3a43
Merge branch 'code-differently:main' into main
AmiyahJo Oct 2, 2024
95f56a5
Merge branch 'code-differently:main' into main
AmiyahJo Oct 3, 2024
0f4dbac
Merge branch 'code-differently:main' into main
AmiyahJo Oct 4, 2024
a3b9984
Merge branch 'code-differently:main' into main
AmiyahJo Oct 4, 2024
54cd199
Merge branch 'code-differently:main' into main
AmiyahJo Oct 4, 2024
edbe7c0
Merge branch 'code-differently:main' into main
AmiyahJo Oct 4, 2024
7f0a084
Merge branch 'code-differently:main' into main
AmiyahJo Oct 7, 2024
a905b74
Merge branch 'code-differently:main' into main
AmiyahJo Oct 8, 2024
2d69531
Merge branch 'code-differently:main' into main
AmiyahJo Oct 8, 2024
df48fbd
Merge branch 'code-differently:main' into main
AmiyahJo Oct 8, 2024
c972d14
Merge branch 'code-differently:main' into main
AmiyahJo Oct 9, 2024
bc3907c
Merge branch 'code-differently:main' into main
AmiyahJo Oct 9, 2024
b4ec394
test: added the missing instructional test
Oct 9, 2024
3afe4fe
Merge branch 'code-differently:main' into feature/lesson_07
AmiyahJo Oct 9, 2024
6fbcef5
feat: created a ` canVote ` if statement
Oct 9, 2024
58b7e17
feat: if statements created for convertGpaToLetterGrade
Oct 9, 2024
172ad2a
feat: add if statements to computeFactorial
Oct 9, 2024
d0e114d
fix: changed spelling to 'return' from computeFactorial
Oct 9, 2024
722b621
feat: adjusting compareStrings statements
Oct 9, 2024
503ac6f
fix: compareStrings if else statement
Oct 10, 2024
1a2426a
fix: compareStrings return methods
Oct 10, 2024
892656b
fix: convertGPAToLetterGrade
Oct 10, 2024
1144702
fix: created a for loop and a variable that holds the factorial of n
Oct 10, 2024
2c2a9bc
fix: testAddNumbers
Oct 10, 2024
8cd4832
fix: fibonacciNumbers made , and comments for understanding
Oct 10, 2024
4a3d988
fix: binarySearch function
Oct 10, 2024
2fcddb3
fix: binarySearch
Oct 10, 2024
1191955
fix: binarySearch
Oct 10, 2024
bc1d17f
Merge branch 'code-differently:main' into feature/lesson_07
AmiyahJo Oct 11, 2024
ccf406d
fix: removed .json file in lesson 06
Oct 11, 2024
ff25c09
fix: .json extra folder removal
Oct 11, 2024
9ff9c80
feat: canVote age one liner
Oct 11, 2024
cda1180
Merge branch 'code-differently:main' into feature/lesson_07
AmiyahJo Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 73 additions & 14 deletions lesson_07/conditionals/src/lesson7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -23,7 +26,11 @@ export function compareStrings(a: string, b: string): number {
const distance = computeLexicographicDistance(a, b);

// TODO(you): Finish this method.

if (distance < 0) {
return -1;
} else if (distance > 0) {
return 1;
}
return 0;
}

Expand All @@ -37,6 +44,27 @@ 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) {
return "A";
} else if (gpa >= 3.7) {
return "A-";
} else if (gpa >= 3.3) {
return "B+";
} else if (gpa >= 3.0) {
return "B";
} else if (gpa >= 2.7) {
return "B-";
} else if (gpa >= 2.3) {
return "C+";
} else if (gpa >= 2.0) {
return "C";
} else if (gpa >= 1.7) {
return "C-";
} else if (gpa >= 1.3) {
return "D+";
} else if (gpa >= 1.0) {
return "D";
}
return "F";
}

Expand All @@ -47,7 +75,17 @@ export function convertGpaToLetterGrade(gpa: number): string {
* @return The factorial of n.
*/
export function computeFactorial(n: number): number {
return 0;
if (n < 0){
return -1;
} else if (n === 0){
return 1;
}

let factorial = 1;
for (let i = 1; i <= n; i++){
factorial *= i;
}
return factorial;
}

/**
Expand All @@ -57,7 +95,12 @@ 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;
}

/**
Expand All @@ -67,7 +110,20 @@ export function addNumbers(values: number[]): number {
* @return An array containing the first `n` Fibonacci values.
*/
export function getFirstNFibonacciNumbers(n: number): number[] {
return [];
const fibonacciNumbers: number[] = new Array(n); //New empty array with a list of n

for (let i = 0; i < n; i++) {
if (i === 0){
fibonacciNumbers[i] = 1; //1st number is 1
} else if (i === 1){
fibonacciNumbers[i] = 1; //2nd number is also 1
} else {
fibonacciNumbers[i] = fibonacciNumbers[i - 1] + fibonacciNumbers[i - 2];
// current number = (previous number) + (number before that)
}
}

return fibonacciNumbers;
}

/**
Expand All @@ -80,10 +136,7 @@ export function getFirstNFibonacciNumbers(n: number): number[] {
* @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,
values: number[], start: number, end: number, value: number,
): number {
if (end < start) {
// The range is not valid so just return -1.
Expand All @@ -93,10 +146,16 @@ export function binarySearch(
const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array.

// 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;
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);
}
// 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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.