Conversation
reposman33
left a comment
There was a problem hiding this comment.
Looks good, just a few remarks about using Array methods instead of for loops.
| let count = 0; | ||
|
|
||
| for (let i = 0; i < numbers.length; i++) { | ||
| if (numbers[i] > threshold) { |
There was a problem hiding this comment.
If you use Array methods the same code can be written like this:
count = numbers.filter(num > num > threshold).length.
I'm not sure if Array prototype methods are already known at this stage of the course but it is definitely preferred over the traditional loop construct
| }; | ||
|
|
||
|
|
||
| console.log(`There is ${countNumbersInArray([90,45,76,3,5,8,2,77,3,65,43,4,45,90], 40)} numbers above the threshold.`); |
There was a problem hiding this comment.
just nitpicking here - "numbers above the threshold" => "numbers above 40"
| text[i] === "a" || | ||
| text[i] === "e" || | ||
| text[i] === "i" || | ||
| text[i] === "o" || |
There was a problem hiding this comment.
There is an easier way - use the include Array method:
if (["a", "e", "i", "o", "u"].includes(text[i])) {}
Ah, I see that in Week 4 - Data structures and loops this is not covered so consider Array methods a bonus https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array.
| console.time("Linear Search"); | ||
| linearSearch(bigArray, 999999); | ||
| console.timeEnd("Linear Search"); | ||
| const bigArray = sizes.map(size => generateBigArray(size)); |
Complete All Tasks For Week 5