Skip to content

task:lesson 07 had to rebuild fork #339

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 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lesson_07/conditionals/.env.test
Original file line number Diff line number Diff line change
@@ -1 +1 @@
HW_VERSION=your homework version here
HW_VERSION=E
54 changes: 46 additions & 8 deletions lesson_07/conditionals/src/lesson7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,33 @@ import { computeLexicographicDistance } from "./util.js";
export function compareStrings(a: string, b: string): number {
// 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);
const distance = computeLexicographicDistance(a, b);

// TODO(you): Finish this method.

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

/**
* Computes the factorial of the given value of `n`.
*
* @param n The value for which to compute the factorial.
* @return The factorial of n.
*/
export function computeFactorial(n: number): number {
return 0;
if (n === 0 ) {
return 1; // Base case: 0! and 1! both equal 1
}
else if (n === 1) {
return 1;
}
else if (n < 0) {
return 0;
}
return n * computeFactorial(n - 1);
}

/**
Expand All @@ -34,6 +46,22 @@ export function computeFactorial(n: number): number {
* @return An array containing the first `n` Fibonacci values.
*/
export function getFirstNFibonacciNumbers(n: number): number[] {
for (let i = 0; i < n; i++) {
if (n === 0) {
return [];
}
else if (n === 1) {
return [1];
}
else if (n === 2) {
return [1, 1];
}
else {
const fib = getFirstNFibonacciNumbers(n - 1);
fib.push(fib[fib.length - 1] + fib[fib.length - 2]);
return fib;
}
}
return [];
}

Expand All @@ -57,9 +85,19 @@ export function binarySearch(
return -1;
}

const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array.

// TODO(you): Finish implementing this algorithm
const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array.
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);
return -1;
}




// If values[pivotIndex] is equal to value then return `pivotIndex`.
// Else if values[pivotIndex] is greater than the value, then
Expand Down
13 changes: 12 additions & 1 deletion lesson_07/conditionals/src/part_e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* @returns
*/
export function isUppercase(char: string): boolean {
if (char >= "A" && char <= "Z") {
return true;
}

return false;
}

Expand All @@ -17,6 +21,9 @@ export function isUppercase(char: string): boolean {
* @returns
*/
export function canGetDriverLicense(age: number, passedTest: boolean): boolean {
if (age >= 18 && passedTest) {
return true;
}
return false;
}

Expand All @@ -29,5 +36,9 @@ export function canGetDriverLicense(age: number, passedTest: boolean): boolean {
* @returns
*/
export function isStoreOpen(day: string, hour: number): boolean {
return false;
if (day === "Sunday" || hour < 9 || hour >= 21) {
return false;
} else {
return true;
}
}