Skip to content

Commit e891f89

Browse files
feat: started homework
1 parent 70dccf2 commit e891f89

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

lesson_07/conditionals/src/lesson7.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { computeLexicographicDistance } from "./util.js";
77
* @return True if the age corresponds to a voting age and false otherwise.
88
*/
99
export function canVote(age: number): boolean {
10+
if (age >= 18) {
11+
return true;
12+
}
1013
return false;
1114
}
1215

@@ -22,6 +25,12 @@ export function compareStrings(a: string, b: string): number {
2225
// if it is greater, and 0 if the strings are equal.
2326
const distance = computeLexicographicDistance(a, b);
2427

28+
if (distance < 0) {
29+
// instructions say 'distance will be A NUMBER less than 0 ' not quite exactly -1
30+
return -1;
31+
}
32+
33+
return distance; // instructions clearly state will be 0 if a === b and 1 if a > b which is what we want
2534
// TODO(you): Finish this method.
2635

2736
return 0;
@@ -37,7 +46,35 @@ export function compareStrings(a: string, b: string): number {
3746
* @return The letter grade ("A+", "A", "A-", "B+", etc.).
3847
*/
3948
export function convertGpaToLetterGrade(gpa: number): string {
40-
return "F";
49+
switch (
50+
true // better way to do this. want to use the equivilent of a Java Map (XavierCruz5106)
51+
) {
52+
case gpa >= 1.0 && gpa < 1.3:
53+
return "D";
54+
case gpa >= 1.3 && gpa < 1.7:
55+
return "D+";
56+
case gpa >= 1.7 && gpa < 2.0:
57+
return "C-";
58+
case gpa >= 2.0 && gpa < 2.3:
59+
return "C";
60+
case gpa >= 2.3 && gpa < 2.7:
61+
return "C+";
62+
case gpa >= 2.7 && gpa < 3.0:
63+
return "B-";
64+
case gpa >= 3.0 && gpa < 3.3:
65+
return "B";
66+
case gpa >= 3.3 && gpa < 3.7:
67+
return "B+";
68+
case gpa >= 3.7 && gpa < 3.9:
69+
return "A-";
70+
case gpa === 3.9:
71+
return "A";
72+
case gpa === 4.0:
73+
return "A+";
74+
75+
default:
76+
return "F";
77+
}
4178
}
4279

4380
/**
@@ -47,7 +84,12 @@ export function convertGpaToLetterGrade(gpa: number): string {
4784
* @return The factorial of n.
4885
*/
4986
export function computeFactorial(n: number): number {
50-
return 0;
87+
let total = 1;
88+
for (let i = 2; i <= n; i++) {
89+
total *= i;
90+
}
91+
92+
return total;
5193
}
5294

5395
/**
@@ -57,7 +99,11 @@ export function computeFactorial(n: number): number {
5799
* @return The sum of all the values.
58100
*/
59101
export function addNumbers(values: number[]): number {
60-
return 0;
102+
let sum = 0;
103+
for (const value in values) {
104+
sum += Number(value);
105+
}
106+
return sum;
61107
}
62108

63109
/**
@@ -67,6 +113,14 @@ export function addNumbers(values: number[]): number {
67113
* @return An array containing the first `n` Fibonacci values.
68114
*/
69115
export function getFirstNFibonacciNumbers(n: number): number[] {
116+
const nums = [];
117+
let prev = 0;
118+
for (let i = 1; i < n; i++) {
119+
const next = i + prev;
120+
prev = i;
121+
122+
console.log(next);
123+
}
70124
return [];
71125
}
72126

0 commit comments

Comments
 (0)