-
Notifications
You must be signed in to change notification settings - Fork 25
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
Chigazo Lesson 07 #274
Changes from 18 commits
887b8f0
05ad627
5715b6a
6c909b0
4c1a3f2
de19403
56aa83d
8529105
4f76813
48bf962
1da88b9
3068765
712efd6
82381df
7dcdcb2
a0ceba6
962d2dc
e5007e4
42534de
51070a9
a7d16ad
58193dd
88ef56b
28d418e
54605f2
cb2e3b4
d74c27a
ef2a1dd
87887b1
1eb4434
b69ab2e
a4056a9
18ecdcb
0c68123
f9b7d7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
* | ||
|
@@ -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; | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -37,7 +47,32 @@ export function compareStrings(a: string, b: string): number { | |
* @return The letter grade ("A+", "A", "A-", "B+", etc.). | ||
*/ | ||
export function convertGpaToLetterGrade(gpa: number): string { | ||
return "F"; | ||
|
||
if(gpa >= 97){ | ||
return "A+" | ||
}else if(gpa >= 93){ | ||
return "A" | ||
}else if(gpa >= 90){ | ||
return "A-" | ||
}else if(gpa >= 87){ | ||
return "B+" | ||
}else if(gpa >= 83){ | ||
return "B" | ||
}else if(gpa >= 80){ | ||
return "B-" | ||
}else if(gpa >= 77){ | ||
return "C+" | ||
}else if(gpa >= 73){ | ||
return "C" | ||
}else if(gpa >= 70){ | ||
return "C-"; | ||
}else if(gpa >= 67){ | ||
return "D+"; | ||
}else if(gpa >= 65){ | ||
return "D"; | ||
}else{ | ||
return "F" | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -47,7 +82,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; | ||
} | ||
|
||
/** | ||
|
@@ -57,7 +98,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; | ||
} | ||
|
||
/** | ||
|
@@ -67,7 +115,14 @@ export function addNumbers(values: number[]): number { | |
* @return An array containing the first `n` Fibonacci values. | ||
*/ | ||
export function getFirstNFibonacciNumbers(n: number): number[] { | ||
return []; | ||
|
||
const array = [n] | ||
|
||
for(let i = 2; i < n; i++){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are you going to do if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added else-if condition for n === 1 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
/** | ||
|
@@ -93,10 +148,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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't want to put
n
here. If the function is called with99
, then the array will be initialized to[99]
which is not what you want.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to start the array as [1, 1] instead of [n]