Skip to content

Manchester | 26-ITP-Jan | Ofonime Edak | Sprint 1 | Data group#1045

Open
Ofonimeedak wants to merge 1 commit intoCodeYourFuture:mainfrom
Ofonimeedak:datagroup/sprint1-coursework
Open

Manchester | 26-ITP-Jan | Ofonime Edak | Sprint 1 | Data group#1045
Ofonimeedak wants to merge 1 commit intoCodeYourFuture:mainfrom
Ofonimeedak:datagroup/sprint1-coursework

Conversation

@Ofonimeedak
Copy link

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

I have made changes to the following files, sum.js,include.js and all test cases
I have followed the acceptance criteria for all katas
This PR contains functions for de-duplication and summation of arrays
It also contained a refactored function and different test cases

@Ofonimeedak Ofonimeedak added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Groups The name of the module. labels Mar 19, 2026
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Why not practice "committing files one by one, on purpose, and for a reason"?
In VSCode, you can select which file to stage, and commit only the staged file.
See: https://www.youtube.com/watch?v=z5jZ9lrSpqk&t=705 (At around 12:50 minute marker, the video shows how to stage a single file).

Comment on lines +11 to +16
const numbers = [];
for (const x of list) {
if (typeof x === "number" && !isNaN(x)) {
numbers.push(Number(x));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The code work.

This is also a good opportunity to practice using the array's .filter() method to simplify the code on lines 11-16.

Comment on lines +1 to +14
function dedupe(arr) {

if(arr.length===0) return arr;
const dedupeArray=[]
for(let i=0;i<arr.length;i++){

if(!dedupeArray.includes(arr[i])){
dedupeArray.push(arr[i])
}
}
return dedupeArray;


}
Copy link
Contributor

Choose a reason for hiding this comment

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

Code is not consistently formatted.

Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode,
as recommended in
https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/blob/main/readme.md
?

Comment on lines +25 to +37
// Given an array with no duplicates
// Then it should return a copy of the original array
[
{ input: [1, 2, 3, 4], expected: [1, 2, 3, 4] },
{
input: ["apples", "banana", "orange"],
expected: ["apples", "banana", "orange"],
},
{ input: [-1, 7, 1], expected: [-1, 7, 1] },
].forEach(({ input, expected }) =>
it(`should return same input values [${input}] without duplicate`, () => {
expect(dedupe(input)).toEqual(expected);
}));
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 15 to +20
// Given an empty array
// When passed to the max function
// Then it should return -Infinity
// Delete this test.todo and replace it with a test.
test.todo("given an empty array, returns -Infinity");
describe("findMax()", () => {
[{ input: [], expected: Infinity }].forEach(({ input, expected }) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the spec on line 17, the function is expected to return -Infinity when given an empty array.

Comment on lines +3 to +10
if (elements.length === 0) return Infinity;
const number = [];
for (let i = 0; i < elements.length; i++) {
if (typeof elements[i] === "number" && !Number.isNaN(elements[i])) {
number.push(elements[i]);
}
}
if (number.length === 0) return "invalid elements";
Copy link
Contributor

Choose a reason for hiding this comment

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

Could consider treating both empty array and arrays that contains only non-numeric values as
"arrays that do not contain any number".

Comment on lines +68 to +88
// Given an array with non-number values
// When passed to the max function
// Then it should return the max and ignore non-numeric values
[
{ input: ["edak", "ofonime", "", "@", -4, 10, 6, 50, -100], expected: 50 },
].forEach(({ input, expected }) =>
it(`should return max numerical value from the array`, () => {
expect(findMax(input)).toEqual(expected);
})
);

// 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
[{ input: ["peter", "", "@", "Hi"], expected: "invalid elements" }].forEach(
({ input, expected }) =>
it(`should return "invalid elements" for non-numeric values`, () => {
expect(findMax(input)).toEqual(expected);
})
);
});
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 +47 to +52
[{ input: [0.5, 0.2, 0.11, 0.89, 0.3], expected: 2 }].forEach(
({ input, expected }) =>
it(`should return ${expected} for [${input}]`, () => {
expect(sum(input)).toEqual(expected);
})
);
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

// Then it should ignore the non-numerical values and return the sum of the numerical elements

[
{ input: ["evan", 3, "mike", 20, 6, "", "/", , , 20], expected: 49 },
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to explicitly specify undefined instead of leaving the element blank.

@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 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Data-Groups The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants