Skip to content

Conversation

@AdnaanA
Copy link

@AdnaanA AdnaanA commented Oct 6, 2025

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

Change list:

In sum.js I have implemented a function that sums only the numeric elements of an array, ignoring non-numerical values, and handles empty arrays, negatives, and decimals, with tests in sum.test.js.

In max.js I have implemented a function that finds the largest numeric element in an array while ignoring non-numeric values and supporting empty arrays, negatives, and decimals, tested in max.test.js.

In dedupe.js I have implemented a function that removes duplicate values from arrays of numbers or strings, preserving the first occurrence and handling empty arrays, with tests in dedupe.test.js.

In calculateMedian.js I have implemented a function that calculates the median of numeric elements from sorted or unsorted arrays of odd or even length, filtering out non-numeric values, tested in median.test.js.

In includes.js I have refactored the function that checks if a target value exists in an array using a for...of loop, supporting empty arrays, duplicates, and nulls, with tests in includes.test.js.

AdnaanA added 17 commits July 1, 2025 16:59
	modified:   Sprint-1/fix/median.test.js
	new file:   package-lock.json
	new file:   package.json
	modified:   Sprint-1/implement/dedupe.test.js
	modified:   Sprint-1/implement/max.test.js
	modified:   Sprint-1/implement/sum.test.js
	modified:   Sprint-2/debug/address.js
	modified:   Sprint-2/implement/contains.test.js
	modified:   Sprint-2/implement/lookup.test.js
	modified:   Sprint-2/implement/querystring.test.js
	modified:   Sprint-2/implement/tally.test.js
	deleted:    Sprint-2/debug/author.js
	deleted:    Sprint-2/debug/recipe.js
	deleted:    Sprint-2/implement/contains.js
	deleted:    Sprint-2/implement/contains.test.js
	deleted:    Sprint-2/implement/lookup.js
	deleted:    Sprint-2/implement/lookup.test.js
	deleted:    Sprint-2/implement/querystring.js
	deleted:    Sprint-2/implement/querystring.test.js
	deleted:    Sprint-2/implement/tally.js
	deleted:    Sprint-2/implement/tally.test.js
	deleted:    Sprint-2/interpret/invert.js
	deleted:    Sprint-2/package-lock.json
	deleted:    Sprint-2/package.json
	deleted:    Sprint-2/readme.md
	deleted:    Sprint-2/stretch/count-words.js
	deleted:    Sprint-2/stretch/mode.js
	deleted:    Sprint-2/stretch/mode.test.js
	deleted:    Sprint-2/stretch/till.js
	modified:   Sprint-1/implement/sum.test.js
@AdnaanA AdnaanA added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 1 Assigned during Sprint 1 of this module labels Oct 6, 2025
@ckirby19 ckirby19 added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 20, 2025
Copy link

@ckirby19 ckirby19 left a comment

Choose a reason for hiding this comment

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

Very, very nice work! All your solutions make sense and your code is very clean. I have just added a few comments for extension

numericList.sort((a, b) => a - b);
const middleIndex = Math.floor(numericList.length / 2);
let median;
if (numericList.length % 2 === 0) {

Choose a reason for hiding this comment

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

This solution is already perfect, but just as an extension, could you show me how you could express this if...else statement using a ternary operator?

Copy link
Author

Choose a reason for hiding this comment

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

Your right we can express the if...else statement using a ternary operator here is how our median calculation will look like using the ternary operator:

numericList.sort((a, b) => a - b);
const middleIndex = Math.floor(numericList.length / 2);

const median = numericList.length % 2 === 0
? (numericList[middleIndex - 1] + numericList[middleIndex]) / 2
: numericList[middleIndex];

Choose a reason for hiding this comment

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

Exactly! Great stuff. In my experience with javascript/typescript, the ternary operator is often preferred over if..else, if there are no "else if" conditions

@@ -1,4 +1,24 @@
function findMax(elements) {
if (elements.length === 0) {

Choose a reason for hiding this comment

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

You may have heard of the DRY (Don't Repeat Yourself) principle in coding, which emphasises reducing the amount of code that is repeated (such as the same if (elements.length === 0) code you have here and below).
Although these if statements represent different cases (an empty array vs. one with all elements that are non-numeric), they can both be covered just with the if statement on line 8

Copy link
Author

Choose a reason for hiding this comment

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

Removed the first if statement since since the if statement at line 8 covered both cases. and i have updated the code accordingly

@ckirby19 ckirby19 added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 23, 2025
@AdnaanA AdnaanA added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 28, 2025
Copy link

@ckirby19 ckirby19 left a comment

Choose a reason for hiding this comment

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

Great work!

@mjpeet
Copy link

mjpeet commented Nov 5, 2025

setting this as complete, all comments seem resolved

@mjpeet mjpeet added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants