Skip to content

Chigazo Lesson 07 #274

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 35 commits into from
Closed
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
887b8f0
Merge pull request #1 from code-differently/main
A1-4U2T1NN Sep 26, 2024
05ad627
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 27, 2024
5715b6a
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
6c909b0
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
4c1a3f2
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
de19403
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
56aa83d
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 1, 2024
8529105
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 2, 2024
4f76813
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 3, 2024
48bf962
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 5, 2024
1da88b9
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 7, 2024
3068765
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 9, 2024
712efd6
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 11, 2024
82381df
feat; added lesson7.ts content
Oct 11, 2024
7dcdcb2
Merge branch 'code-differently:main' into lesson_07
A1-4U2T1NN Oct 11, 2024
a0ceba6
fix: changed 'let' to 'const' on l.119 & l.126; implemented 'distance…
Oct 11, 2024
962d2dc
Merge branch 'lesson_07' of https://github.com/A1-4U2T1NN/code-differ…
Oct 11, 2024
e5007e4
fix: converted 'if' statements into 'else if' statements l.53-71; re…
Oct 11, 2024
42534de
fix: converted scale from % to 4.0 l.53-71; 'included correct 'if' st…
Oct 11, 2024
51070a9
feat: added condition for 'if (n <= 0){}
Oct 11, 2024
a7d16ad
fix: corrected scale values l.53-71;
Oct 11, 2024
58193dd
fix: corrected A to A+ scale;
Oct 11, 2024
88ef56b
fix: updated scale values;
Oct 11, 2024
28d418e
test: testing gpa scale value (tgsv.v1)
Oct 11, 2024
54605f2
(tgsv.v2);
Oct 11, 2024
cb2e3b4
test: (tgsv.v3);
Oct 11, 2024
d74c27a
test:(tgsv.4)
Oct 12, 2024
ef2a1dd
test:(tgsv.5)
Oct 12, 2024
87887b1
fix: added additional parameters in 'else-if' statements to correct e…
Oct 12, 2024
1eb4434
fix: added fixes to the final 'else-if' statement
Oct 12, 2024
b69ab2e
fix: added ';' to the 'else-if' statements;
Oct 12, 2024
a4056a9
fix: removed fixes to the final 'else-if' statement
Oct 12, 2024
18ecdcb
fix: removed final 'else-if' statement;
Oct 12, 2024
0c68123
fix: rebuilt 'else-if' statements for converGpaToLetterGrade;
Oct 12, 2024
f9b7d7d
Merge branch 'code-differently:main' into lesson_07
A1-4U2T1NN Oct 12, 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
78 changes: 70 additions & 8 deletions lesson_07/conditionals/src/lesson7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import { computeLexicographicDistance } from "./util.js";
* @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 @@ -24,7 +28,13 @@ export function compareStrings(a: string, b: string): number {

// TODO(you): Finish this method.

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

/**
Expand All @@ -37,6 +47,28 @@ 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 +79,13 @@ export function convertGpaToLetterGrade(gpa: number): string {
* @return The factorial of n.
*/
export function computeFactorial(n: number): number {
return 0;

let totalValue = 1

for(let i = 1; n >= i; i++){
totalValue *= i
}
return totalValue;
}

/**
Expand All @@ -57,7 +95,14 @@ 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 i of values){
sum += i;
}

return sum;
}

/**
Expand All @@ -67,7 +112,19 @@ export function addNumbers(values: number[]): number {
* @return An array containing the first `n` Fibonacci values.
*/
export function getFirstNFibonacciNumbers(n: number): number[] {
return [];

const array = [1, 1]

if (n <= 0){
return [];
}else if(n === 1){
return [1]
}
for(let i = 2; i < n; i++){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you going to do if n === 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added else-if condition for n === 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added to return [1]

const cont = array[i - 1] + array[i - 2];
array.push(cont)
}
return array;
}

/**
Expand All @@ -93,10 +150,15 @@ 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] === value){
return pivotIndex;
} 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;
}