-
-
Notifications
You must be signed in to change notification settings - Fork 178
London|ITP-September-2025|Alexandru Pocovnicu|Sprint 1 #806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
71fa218
927769b
a393af9
057a7dd
bc5e43c
b13a731
552eb4c
1e0393e
b78089c
4f6b45e
5d670ec
879eb0e
157b5f7
c85cfda
5619c22
abd3a43
ee2fd08
584bd6f
908c81e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "folders": [ | ||
| { | ||
| "name": "Sprint-1", | ||
| "path": "./Sprint-1" | ||
| }, | ||
| { | ||
| "name": "Sprint-2", | ||
| "path": "./Sprint-2" | ||
| }, | ||
| { | ||
| "name": "Sprint-3", | ||
| "path": "./Sprint-3" | ||
| } | ||
| ], | ||
| "settings": { | ||
| "jest.disabledWorkspaceFolders": ["Sprint-2", "Sprint-3"], | ||
| "jest.jestCommandLine": "npm test --" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,11 @@ | ||
| function dedupe() {} | ||
| function dedupe(arr) { | ||
| if (arr.length === 0) { | ||
| return []; | ||
| } | ||
| const arrCopy = arr.slice(0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 7 will create a new array. We don't have to create another array here. |
||
| console.log(arrCopy); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need this console.log() statement for the function to work? |
||
| return [...new Set(arrCopy)]; | ||
| } | ||
| module.exports = dedupe; | ||
|
|
||
| console.log(dedupe([1, 2, 3, 4, 4, 2])); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,20 @@ E.g. dedupe([1, 2, 1]) target output: [1, 2] | |
| // Given an empty array | ||
| // When passed to the dedupe function | ||
| // Then it should return an empty array | ||
| test.todo("given an empty array, it returns an empty array"); | ||
| test("given an empty array, it returns an empty array", () => { | ||
| expect(dedupe([])).toEqual([]); | ||
| }); | ||
|
|
||
| // 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,return a copy of the original array", () => { | ||
| expect(dedupe([1, "y", 4, 7])).toEqual([1, "y", 4, 7]); | ||
| }); | ||
|
Comment on lines
+26
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current test code cannot check if the returned array is a copy of the original array because In order to check if the returned array is a copy of the original array, we would need additional checks. |
||
|
|
||
| // Given an array with strings or numbers | ||
| // When passed to the dedupe function | ||
| // Then it should remove the duplicate values, preserving the first occurence of each element | ||
| test("Given an array with strings or numbers,return an array without duplicates", () => { | ||
| expect(dedupe([1, 1, "l", 5, 7, "l"])).toEqual([1, "l", 5, 7]); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,17 @@ | ||
| function findMax(elements) { | ||
| if (elements.length === 0) { | ||
| return -Infinity; | ||
| } else if (elements.length === 1) { | ||
| return elements[0]; | ||
| } | ||
| if (elements.every((element) => typeof element !== "number")) { | ||
| return NaN; | ||
| } | ||
| let filteredElements = elements.filter( | ||
| (element) => typeof element === "number" | ||
| ); | ||
| let orderedElements = filteredElements.sort((a, b) => a - b); | ||
| return orderedElements[orderedElements.length - 1]; | ||
|
Comment on lines
+2
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
findMax([ "Foo" ]);
findMax([ "Foo", "Bar" ]);
findMax([ NaN, 1, 2, 3, NaN ]); |
||
| } | ||
|
|
||
| module.exports = findMax; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,22 @@ | ||
| function sum(elements) { | ||
| } | ||
| if (elements.length === 0) { | ||
| return 0; | ||
| } | ||
| if (elements.length === 1) { | ||
| return elements[0]; | ||
| } | ||
|
Comment on lines
+2
to
+7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why give special treatment to an array with one element? |
||
| if (elements.every((element) => typeof element !== "number")) { | ||
| return NaN; | ||
| } | ||
| const filteredElements = elements.filter( | ||
| (element) => typeof element === "number" | ||
| ); | ||
|
Comment on lines
+8
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When an array contains at least one number, the code on lines 8-13 would end up processing the array elements twice. |
||
| let addElements = 0; | ||
| for (let element of filteredElements) { | ||
| addElements = addElements + element; | ||
| } | ||
|
|
||
| return addElements; | ||
| } | ||
| module.exports = sum; | ||
| console.log(sum([-9, -3, -4])); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,24 +13,41 @@ const sum = require("./sum.js"); | |
| // Given an empty array | ||
| // When passed to the sum function | ||
| // Then it should return 0 | ||
| test.todo("given an empty array, returns 0") | ||
| test("given an empty array, returns 0", () => { | ||
| expect(sum([])).toEqual(0); | ||
| }); | ||
|
|
||
| // Given an array with just one number | ||
| // When passed to the sum function | ||
| // Then it should return that number | ||
| test("Given an array with just one number,return that number", () => { | ||
| expect(sum([5])).toEqual(5); | ||
| }); | ||
|
|
||
| // Given an array containing negative numbers | ||
| // When passed to the sum function | ||
| // Then it should still return the correct total sum | ||
| test("Given an array containing negative numbers,return the correct total sum", () => { | ||
| expect(sum([-6, -7, -2])).toEqual(-15); | ||
| }); | ||
|
|
||
| // 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,return the correct total sum", () => { | ||
| expect(sum([-1.5, 1.5, 4.5])).toEqual(4.5); | ||
| }); | ||
|
Comment on lines
+37
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 So the following could happen Can you find a more appropriate way to test a value (that involves decimal number calculations) for equality? Suggestion: Look up
|
||
|
|
||
| // Given an array containing non-number values | ||
| // When passed to the sum function | ||
| // Then it should ignore the non-numerical values and return the sum of the numerical elements | ||
| test("Given an array containing non-number values,it should ignore the non-numerical values and return the sum of the numerical elements", () => { | ||
| expect(sum([null, "g", "9", 1.2, 1.8, -3])).toEqual(0); | ||
| }); | ||
|
|
||
| // Given an array with only non-number values | ||
| // When passed to the sum 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 values,return Nan", () => { | ||
| expect(sum(["g", undefined, null, "7", []])).toBeNaN(); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
middleIndex.