Skip to content

feat: adds Meiko's lesson 07 #313

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 1 commit 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=C
16 changes: 8 additions & 8 deletions lesson_07/conditionals/package-lock.json

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

2 changes: 1 addition & 1 deletion lesson_07/conditionals/package.json
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert changes to this file and package-lock.json.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"eslint-config-prettier": "^9.1.0",
"jest": "^29.7.0",
"prettier": "3.4.2",
"ts-jest": "^29.2.5",
"ts-jest": "^29.2.6",
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.0"
Expand Down
45 changes: 38 additions & 7 deletions lesson_07/conditionals/src/lesson7.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { log } from "console";
import { computeLexicographicDistance } from "./util.js";

/**
Expand All @@ -13,28 +14,48 @@ export function compareStrings(a: string, b: string): number {
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix indentation/formatting here and elsewhere.

return 0;
}
if (n === 0) {
return 1;
}
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 [];
if(n <= 0) return [];
if(n === 1) return[1];
const fib: number[] = [1,1];
for(let i = 2; i < n; i++){
fib.push(fib[i - 1] + fib[i - 2]);
}
return fib;
}

/**
Expand All @@ -58,12 +79,22 @@ export function binarySearch(
}

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

const pivotValue = values[pivotIndex];
if (pivotValue === value) {
return pivotIndex;
}
if (pivotValue > value) {
return binarySearch(values, start, pivotIndex - 1, value);
}
if (pivotValue < value){
return binarySearch(values, pivotIndex + 1, end, value);
}
return -1;
}
// TODO(you): Finish implementing this algorithm

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

37 changes: 35 additions & 2 deletions lesson_07/conditionals/src/part_c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
* @returns
*/
export function isStrongPassword(password: string): boolean {
return false;

if (password.length < 8){
return false;
}
const passUpperCase = /[A-Z]/.test(password);
const passNumber=/\d/.test(password);
return passUpperCase && passNumber;
}


/**
* Determines the day of the week on the given 0-based number.
Expand All @@ -16,8 +23,24 @@ export function isStrongPassword(password: string): boolean {
* @returns
*/
export function getDayOfWeek(day: number): string {
if(day==0){
return "Sunday";
} else if(day==1){
return "Monday";
} else if(day==2){
return "Tuesday";
} else if(day==3){
return "Wednesday"
} else if(day==4){
return "Thursday";
}else if(day==5){
return "Friday";
} else if(day==6){
return "Saturday";
}else{
return "";
}
}

/**
* Determines the ticket price based on the given age. The price is
Expand All @@ -31,5 +54,15 @@ export function getDayOfWeek(day: number): string {
* @returns
*/
export function getTicketPrice(age: number): number {
return 0;
if(age <= 5){
return 0;
}else if(age >= 5 && age <= 17){
return 10;
}else if(age >= 18 && age <= 59){
return 20;
}else{
return 15;
}
}