Skip to content

Sheffield | 26-Jan-ITP | Martha Ogunbiyi| Sprint 1 | Coursework/sprint 1#1054

Open
marthak1 wants to merge 6 commits intoCodeYourFuture:mainfrom
marthak1:coursework/sprint-1
Open

Sheffield | 26-Jan-ITP | Martha Ogunbiyi| Sprint 1 | Coursework/sprint 1#1054
marthak1 wants to merge 6 commits intoCodeYourFuture:mainfrom
marthak1:coursework/sprint-1

Conversation

@marthak1
Copy link

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

implemented sprint 1 course work

@marthak1 marthak1 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 20, 2026
if (numericValues.length === 0) return null;

// Step 4: sort safely
const sortedList = numericValues.slice().sort((a, b) => a - b);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make a copy of numericValues before sorting?

Comment on lines 25 to +32
// Given an array with no duplicates
// When passed to the dedupe function
// Then it should return a copy of the original array
test("given an array with no duplicates, it returns return a copy of the original array", () => {
const input = [1, 2, 3, 4, 5];
const result = dedupe(input);
expect(result).toEqual([1, 2, 3, 4, 5]);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should fail if the function returns the original array (instead of a copy of the original array).

The current test checks only if both the original array and the returned array contain identical elements.
In order to validate the returned array is a different array, we need an additional check.

Can you find out what this additional check is?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 40 to +47
// Given an array with decimal/float numbers
// When passed to the sum function
// Then it should return the correct total sum
test("given an array with decimal/float numbers, it should return the correct total sum", () => {
const input = [5, 6.6, 10, 5.12];
const result = sum(input);
expect(result).toBe(26.720000000000002);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decimal numbers in most programming languages (including JS) are internally represented in "floating point number" format. Floating point arithmetic is not exact. For example, the result of 46.5678 - 46 === 0.5678 is false because 46.5678 - 46 only yield a value that is very close to 0.5678. Even changing the order in which the program add/subtract numbers can yield different values.

So the following could happen

  expect( 1.2 + 0.6 + 0.005 ).toEqual( 1.805 );                // This fail
  expect( 1.2 + 0.6 + 0.005 ).toEqual( 1.8049999999999997 );   // This pass
  expect( 0.005 + 0.6 + 1.2 ).toEqual( 1.8049999999999997 );   // This fail

  console.log(1.2 + 0.6 + 0.005 == 1.805);  // false
  console.log(1.2 + 0.6 + 0.005 == 0.005 + 0.6 + 1.2); // false

Can you find a more appropriate way to test a value (that involves decimal number calculations) for equality?

Suggestion: Look up

  • Checking equality in floating point arithmetic in JavaScript
  • Checking equality in floating point arithmetic with Jest

Comment on lines +13 to +19

// const array = ["a", "b", "c"];

// for (const element of array) {
// console.log(element);
// } for (variable of iterable) statement

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best practice to remove unnecessary code to keep the code clean.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants