Repository navigation
London | 26-ITP-Sep | Mahir Shah | Sprint 1 | Data Groups - #1481
MahirShah300 wants to merge 24 commits into
Conversation
| sortedElements = elements.toSorted((a, b) => a - b); | ||
|
|
||
| return sortedElements[sortedElements.length - 1]; |
There was a problem hiding this comment.
This work.
Suggestion: Explore a more efficient approach to find the largest numbers in an array.
There was a problem hiding this comment.
Used Math.max(...elements) as a more efficient method
There was a problem hiding this comment.
Note: Math.max() works well for numbers.
It is equally important to know how to use a loop to find the extreme value within an array without sorting. Do you know how to implement such a loop? (No change required)
There was a problem hiding this comment.
Something such as
let largestNumber = elements[0]
for (const number of elements){
if(number > largestNumber){
largestNumber = number
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good.
Just one more question.
| (currentValue) => | ||
| typeof currentValue === "number" && !Number.isNaN(currentValue) | ||
| (value) => | ||
| typeof value === "number" && !Number.isNaN(value) && Number.isFinite(value) |
There was a problem hiding this comment.
Could you find out which of these checks are redundant?
There was a problem hiding this comment.
typeof value === "number" and !Number.isNaN(value) are the redundant checks, Number.isFinite() returns false for NaN, + and - infinity and non numbers
|
All good. |
Learners, PR Template
Self checklist
Task code
CYF-1071
Changelist
Implemented tests and functions.