Skip to content

feat: Lesson 7 Homework - Partial for Dwight #292

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 4 commits into from
Closed
Changes from all commits
Commits
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
55 changes: 49 additions & 6 deletions lesson_07/conditionals/src/lesson7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
* @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;
}
}

/**
* Compares two strings lexicographically.
*
Expand All @@ -21,7 +25,13 @@
// 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) {
return -1;
} else if (distance > 0) {
return 1;
} else {
return 0;
}
// TODO(you): Finish this method.

return 0;
Expand All @@ -37,7 +47,31 @@
* @return The letter grade ("A+", "A", "A-", "B+", etc.).
*/
export function convertGpaToLetterGrade(gpa: number): string {
return "F";
let letterGrade = "";
if (gpa > 3.99) {
letterGrade = "A";
} else if (gpa > 3.69 && gpa < 4) {
letterGrade = "A-";
} else if (gpa > 3.29 && gpa < 3.7) {
letterGrade = "B+";
} else if (gpa > 2.99 && gpa < 3.3) {
letterGrade = "B";
} else if (gpa > 2.69 && gpa < 3.0) {
letterGrade = "B-";
} else if (gpa > 2.29 && gpa < 2.7) {
letterGrade = "C+";
} else if (gpa > 1.99 && gpa < 2.3) {
letterGrade = "C";
} else if (gpa > 1.69 && gpa < 2.0) {
letterGrade = "C-";
} else if (gpa > 1.29 && gpa < 1.7) {
letterGrade = "D+";
} else if (gpa > 0.99 && gpa < 1.3) {
letterGrade = "D";
} else if (gpa < 1) {
letterGrade = "F";
}
return letterGrade;
}

/**
Expand All @@ -47,7 +81,12 @@
* @return The factorial of n.
*/
export function computeFactorial(n: number): number {
return 0;
let integer;
let factorial = 1;
for (integer = n; integer > 1; integer--) {
factorial *= integer;
}
return factorial;
}

/**
Expand All @@ -57,7 +96,11 @@
* @return The sum of all the values.
*/
export function addNumbers(values: number[]): number {
return 0;
let sum = 0;
for (let x = 0; values.length > x; x++) {
sum += values[x];
}
return sum;
}

/**
Expand All @@ -66,7 +109,7 @@
* @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[] {

Check failure on line 112 in lesson_07/conditionals/src/lesson7.ts

View workflow job for this annotation

GitHub Actions / build

'n' is defined but never used
return [];
}

Expand All @@ -83,14 +126,14 @@
values: number[],
start: number,
end: number,
value: number,

Check failure on line 129 in lesson_07/conditionals/src/lesson7.ts

View workflow job for this annotation

GitHub Actions / build

'value' is defined but never used
): 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.

Check failure on line 136 in lesson_07/conditionals/src/lesson7.ts

View workflow job for this annotation

GitHub Actions / build

'pivotIndex' is assigned a value but never used

// TODO(you): Finish implementing this algorithm

Expand Down
Loading