Skip to content

feat: upload lesson_07 test #321

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
166 changes: 31 additions & 135 deletions lesson_07/conditionals/package-lock.json
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert changes to this file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 57 additions & 4 deletions lesson_07/conditionals/src/lesson7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,74 @@ export function compareStrings(a: string, b: string): number {
// if it is greater, and 0 if the strings are equal.
const distance = computeLexicographicDistance(a, b);

// TODO(you): Finish this method.

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.
*
* 5! = 5*4! factorial equation
*/
export function computeFactorial(n: number): number {
return 0;
if (n === 0) {
return 1;
}
else if (n === 1) {
return 1;
}
else if (n < 0) {
return 0;
}
else {
return n * computeFactorial(n-1);
}
}



/**
* Returns an array of the first `n` Fibonacci numbers starting from 1.
*
* @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[] {
return [];

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 @@ -58,6 +103,14 @@ export function binarySearch(
}

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;
}

// TODO(you): Finish implementing this algorithm

Expand Down
30 changes: 26 additions & 4 deletions lesson_07/conditionals/src/part_e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
* @param char
* @returns
*/

export function isUppercase(char: string): boolean {
return false;
}
if(['A', 'B', 'C', 'D', 'E', 'F','G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S','T', 'U', 'V', 'W', 'X', 'Y', 'Z'].includes(char)) {
return true;
} else {
return false;
}
}


/**
* Determine if a person is eligible for a driving license (age and test passed).
Expand All @@ -17,7 +23,12 @@ export function isUppercase(char: string): boolean {
* @returns
*/
export function canGetDriverLicense(age: number, passedTest: boolean): boolean {
return false;
if (age >= 18 && passedTest) {
return true;
}
else {
return false;
}
}

/**
Expand All @@ -29,5 +40,16 @@ export function canGetDriverLicense(age: number, passedTest: boolean): boolean {
* @returns
*/
export function isStoreOpen(day: string, hour: number): boolean {
return false;
const weekCaseDay = day.toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix formatting and indentation in this function.



if(weekCaseDay === 'sunday') {
return false;
}
else if (['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'].includes(weekCaseDay) && hour >= 21 || hour < 9)
return false;
else {
return true;
}
}