Skip to content

Lesson07 #333

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
22 changes: 12 additions & 10 deletions lesson_06/quiz/src/lesson5.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR must only include changes for lesson_07. Please revert this file.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Lesson5 {
[AnswerChoice.C, "To insert an image"],
[AnswerChoice.D, "To create a paragraph"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -52,7 +52,7 @@ export class Lesson5 {
[AnswerChoice.C, "alt"],
[AnswerChoice.D, "href"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.C,
);
}

Expand All @@ -66,7 +66,7 @@ export class Lesson5 {
[AnswerChoice.C, "<div>"],
[AnswerChoice.D, "<link>"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -80,7 +80,7 @@ export class Lesson5 {
[AnswerChoice.C, "<span>"],
[AnswerChoice.D, "<br>"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -94,7 +94,7 @@ export class Lesson5 {
[AnswerChoice.C, "Computer Style Sheets"],
[AnswerChoice.D, "Cascading System Sheets"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -108,7 +108,7 @@ export class Lesson5 {
[AnswerChoice.C, "text-color"],
[AnswerChoice.D, "background-color"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -122,7 +122,7 @@ export class Lesson5 {
[AnswerChoice.C, "/* this is a comment */"],
[AnswerChoice.D, "<!-- this is a comment -->"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.C,
);
}

Expand All @@ -136,7 +136,7 @@ export class Lesson5 {
[AnswerChoice.C, "text-size"],
[AnswerChoice.D, "text-style"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -150,7 +150,7 @@ export class Lesson5 {
[AnswerChoice.C, "inline-block"],
[AnswerChoice.D, "none"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -164,11 +164,13 @@ export class Lesson5 {
[AnswerChoice.C, "<stylesheet link='styles.css'>"],
[AnswerChoice.D, "<css href='styles.css'>"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.A,
);
}
}

if (!process.env.JEST_WORKER_ID) {
new Lesson5().run();
}


3 changes: 2 additions & 1 deletion lesson_07/README.md
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.

Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Please review the following resources before lecture:
This exercise will provide you ample opportunities to practice your understanding of conditional expressions and loops. To complete this assignment, implement the functions in [lesson7.ts][lesson7-file] and in the code file for your assigned homework group, ensure the tests pass, and submit a PR. Remember to use the [Conventional Commits][conventional-commits] spec for your commit messages and pull requests.

[lesson7-file]: ./conditionals/src/lesson7.ts
[conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/
[conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/

55 changes: 49 additions & 6 deletions lesson_07/conditionals/src/lesson7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ 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,9 +30,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 || n===1) {
return 1
}
else {
return n * computeFactorial(n-1);
}
}




/**
* Returns an array of the first `n` Fibonacci numbers starting from 1.
*
Expand All @@ -35,7 +49,24 @@ export function computeFactorial(n: number): number {
*/
export function getFirstNFibonacciNumbers(n: number): number[] {
return [];
}
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;
}
}

}


/**
* Finds a value in an array of values.
Expand All @@ -59,7 +90,19 @@ 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;
} else if (values[pivotIndex] > value) {
return binarySearch( values, start, pivotIndex -1, value);
else { binarySearch(values, start, pivotIndex - 1, value)}
return 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
Expand Down
29 changes: 28 additions & 1 deletion lesson_07/conditionals/src/part_a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
* @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;
}
}
console.log(canVote(18))
Copy link
Contributor

Choose a reason for hiding this comment

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

This line should not be here, please remove.


/**
* Adds all of the provided values and returns the sum.
Expand All @@ -15,15 +22,35 @@ export function canVote(age: number): boolean {
* @return The sum of all the values.
*/
export function addNumbers(values: number[]): number {


for (let i = 0; i < values.length ; i++) {


Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't have all of these extra line breaks, fix formatting.

return values[i];
}


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 {

if (n <0 ){

return 0;
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.

}

let factorial = 1


return 0;
}

Loading