Skip to content

FEAT: Added functions for lesson7.test.ts & part_a.ts (JBEY) #317

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
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=A
8 changes: 6 additions & 2 deletions 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.

Must revert changes to this file, package-lock.json, and lesson7.test.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello Anthony. I just "reverted" the changes to match the original repo, but now the tests are failing. I'm not exactly sure what I did wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still not the right revision. I'll close this PR for now. If you want, you can keep trying to fix THIS PR and re-send for review.

Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
"license": "ISC",
"devDependencies": {
"@alfonso-presa/soft-assert": "^0.6.0",
"@babel/core": "^7.26.10",
"@babel/preset-env": "^7.26.9",
"@babel/preset-typescript": "^7.26.0",
"@eslint/js": "^9.17.0",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.14",
"@types/node": "22.10.2",
"babel-jest": "^29.7.0",
"copyfiles": "^2.4.1",
"eslint": "^9.17.0",
"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": "^5.7.3",
"typescript-eslint": "^8.18.0"
},
"dependencies": {
Expand Down
49 changes: 39 additions & 10 deletions lesson_07/conditionals/src/lesson7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ 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.

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

/**
Expand All @@ -24,7 +28,17 @@ export function compareStrings(a: string, b: string): number {
* @return The factorial of n.
*/
export function computeFactorial(n: number): number {
return 0;
if (n < 0) {
return 0;
}

let factorial = 1;

for (let i = 1; i < n; n--) {
factorial = factorial * n;
}

return factorial;
}

/**
Expand All @@ -34,7 +48,15 @@ export function computeFactorial(n: number): number {
* @return An array containing the first `n` Fibonacci values.
*/
export function getFirstNFibonacciNumbers(n: number): number[] {
return [];
if (n === 0) {
return [];
}

const fibNums = [1, 1];
for (let i = 2; i < n; i++) {
fibNums.push(fibNums[i - 1] + fibNums[i - 2]);
}
return fibNums;
}

/**
Expand All @@ -61,9 +83,16 @@ export function binarySearch(

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

// 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.
25 changes: 22 additions & 3 deletions lesson_07/conditionals/src/part_a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* @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;
}
}

/**
Expand All @@ -15,7 +19,12 @@ export function canVote(age: number): boolean {
* @return The sum of all the values.
*/
export function addNumbers(values: number[]): number {
return 0;
let total = 0;

for (const test of values) {
total = total + test;
}
return total;
}

/**
Expand All @@ -25,5 +34,15 @@ export function addNumbers(values: number[]): number {
* @return The factorial of n.
*/
export function computeFactorial(n: number): number {
return 0;
if (n < 0) {
return 0;
}

let factorial = 1;

for (let i = 1; i < n; n--) {
factorial = factorial * n;
}

return factorial;
}
Loading