Sheffield | 26-Jan-ITP | Martha Ogunbiyi| Sprint 1 | Coursework/sprint 1#1054
Open
marthak1 wants to merge 12 commits intoCodeYourFuture:mainfrom
Open
Sheffield | 26-Jan-ITP | Martha Ogunbiyi| Sprint 1 | Coursework/sprint 1#1054marthak1 wants to merge 12 commits intoCodeYourFuture:mainfrom
marthak1 wants to merge 12 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
reviewed
Mar 20, 2026
Comment on lines
61
to
+77
| // Given an array with non-number values | ||
| // When passed to the max function | ||
| // Then it should return the max and ignore non-numeric values | ||
| test("given an array with non-number value, it should return the max and ignore non-numeric value", () => { | ||
| const input = [4, 5, 'arr', 2, []," ", 15, 8]; | ||
| const result = findMax(input); | ||
| expect(result).toBe(15); | ||
| }); | ||
|
|
||
| // Given an array with only non-number values | ||
| // When passed to the max function | ||
| // Then it should return the least surprising value given how it behaves for all other inputs | ||
| test("given an array with only non-number value, it should return the least surprising value given how it behaves for all other inputs", () => { | ||
| const input = [true, {}, "arr", null, [], " ", NaN]; | ||
| const result = findMax(input); | ||
| expect(result).toBe(-Infinity); | ||
| }); No newline at end of file |
Contributor
There was a problem hiding this comment.
When a string representing a valid numeric literal (for example, "300") is compared to a number,
JavaScript first converts the string into its numeric equivalent before performing the comparison.
As a result, the expression 20 < "300" evaluates to true.
To test if the function can correctly ignore non-numeric values,
consider including a string such as "300" in the relevant test cases.
Author
There was a problem hiding this comment.
Thanks for the feedback. I have refactored the implementation to not only check the 'type' , but to also check whether it can become a valid number
…ing floating-point numbers
…ing floating-point numbers
Contributor
|
Changes look good. Well done. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Learners, PR Template
Self checklist
Changelist
implemented sprint 1 course work