Conversation
mo92othman
left a comment
There was a problem hiding this comment.
Hey @Barboud ,
Good job working on this week’s assignment!
You show a solid understanding of the core concepts, especially the search algorithms.
There are a few issues in Task 4 related to the experiment setup, I’ve left some comments there for you to review.
Overall, well done 👏
| test("Find the average from an empty array", () => { | ||
| // Arrange | ||
| const numbers = [5]; | ||
|
|
||
| // Act | ||
| const result = calculateAverage(numbers); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(5); | ||
| }); |
There was a problem hiding this comment.
Good structure! And if I run the tests, all will pass...
However, your empty array test is incorrect, because you're not actually testing/passing an empty array.
The function should return null for [].
| console.time("Linear Search 1k"); | ||
| getTargetByLinearSearch(generateBigArray(1000), 10540640); | ||
| console.timeEnd("Linear Search 1k"); |
There was a problem hiding this comment.
Array creation is included in the timing, this is wrong. Right now you are doing this:
getTargetByLinearSearch(generateBigArray(1000), 10540640);This means you are measuring: Array creation time + Search time. You should create the array first, then measure only the search:
const arr1k = generateBigArray(1000);
console.time("Linear Search 1k");
getTargetByLinearSearch(arr1k, 10540640);
console.timeEnd("Linear Search 1k");| console.time("Linear Search 1M"); | ||
| getTargetByLinearSearch(generateBigArray(10000000), 10540640); | ||
| console.timeEnd("Linear Search 1M"); |
There was a problem hiding this comment.
The label says 1M, but it does not match the array size. generateBigArray(10000000) That is 10M, not 1M.
task-4/search-experiment.js
Outdated
| console.log("---"); | ||
|
|
||
| console.time("Binary Search 1k"); | ||
| getTargetByBinarySearch(getTargetByBinarySearch(1000), 10540640); |
There was a problem hiding this comment.
You hav a small bug here, you should pass an array to getTargetByBinarySearch. But you are passing getTargetByBinarySearch(1000) and that is not an array.
There was a problem hiding this comment.
Thanks for the feedback. Most of the mistakes were because I was just copying and pasting without paying much attention.
No description provided.