-
Notifications
You must be signed in to change notification settings - Fork 23
feat/David.A_lesson7hw #326
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
Dadenaike251
wants to merge
7
commits into
code-differently:main
from
Dadenaike251:release/David.A-lesson7hw
Closed
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ffbdf89
hw incomplete
18ed9d0
Merge branch 'code-differently:main' into release/David.A-lesson7hw
Dadenaike251 4812604
fix: Completed homework & Passed all Tests
620c286
Merge branch 'release/David.A-lesson7hw' of https://github.com/Dadena…
e0406f2
Merge branch 'code-differently:main' into release/David.A-lesson7hw
Dadenaike251 74c58ee
Merge branch 'code-differently:main' into release/David.A-lesson7hw
Dadenaike251 07dcb87
feat/David.A_lesson7hw
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
HW_VERSION=your homework version here | ||
HW_VERSION=A |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,14 @@ 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); | ||
|
||
if (distance < 0) { | ||
return -1; | ||
} else if (distance > 0) { | ||
return 1; | ||
} else { | ||
return 0; | ||
} | ||
// TODO(you): Finish this method. | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
|
@@ -24,7 +28,28 @@ 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 1; | ||
} | ||
else if (n === 1) { | ||
return 1; | ||
} | ||
else if (n < 0) { | ||
return 0; | ||
} | ||
else { | ||
return n * computeFactorial(n-1); | ||
} | ||
// if (n < 0) { | ||
// return 0; | ||
// } | ||
// let numbers = 1; | ||
|
||
// for (let i = 1; i < n; n--) { | ||
// numbers = numbers * n; | ||
// } | ||
|
||
// return numbers; | ||
} | ||
|
||
/** | ||
|
@@ -34,7 +59,39 @@ export function computeFactorial(n: number): number { | |
* @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[]; | ||
|
||
// if (n === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must not have commented out code in your final PR. |
||
// return []; | ||
// } | ||
// else if(n === 1) { | ||
// return [1]; | ||
// } else if (n === 2) { | ||
// return [2] | ||
// } else { | ||
// const number: number[] = [1, 1]; | ||
// for (let i = 3; i < n; i++) { | ||
// number.push(number[i - 1] + number[i - 2]);; | ||
|
||
// } | ||
// return number; | ||
// } | ||
} | ||
|
||
/** | ||
|
@@ -46,6 +103,7 @@ export function getFirstNFibonacciNumbers(n: number): number[] { | |
* @param value The value to look for. | ||
* @return The index of the value if found in the array and -1 otherwise. | ||
*/ | ||
|
||
export function binarySearch( | ||
values: number[], | ||
start: number, | ||
|
@@ -57,13 +115,24 @@ export function binarySearch( | |
return -1; | ||
} | ||
|
||
const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array. | ||
const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array. //this is a variable "pivotIndex" that finds the middle values of our array | ||
if (values[pivotIndex] === value) { | ||
//this function checks if middle value index of our array is equal to the value in our array | ||
return pivotIndex; // returns said value if it is | ||
} else if (values[pivotIndex] > value) { | ||
// checks if middle value is greater than our targett value, if it is than our target is in left half | ||
return binarySearch(values, start, pivotIndex - 1, value); //calls the binarySearch function but range is narrowed down to left side from start to pivotIndex -1 | ||
} else { | ||
//if middle value is less than the target value then the target must be in the right half | ||
return binarySearch(values, pivotIndex + 1, end, value); // calls function binarySearch again and limit range to right side from pivotIndex +1 to end | ||
} | ||
|
||
// 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; | ||
|
||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.