Repository navigation
London | 26-ITP-May | Russom Gebremeskel | Sprint 1 | Coursework #1339
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
Changes from 36 commits
c9145df
1cf01db
256ef50
973df91
535f62f
ff4538c
f713ab1
022321e
3234e57
e60e7e1
15d96c8
d336151
f075a6e
3b5f6cd
455f1b8
8351878
dccd5c5
c31c00a
129f635
aa46855
c37845d
763e7ce
1a697cc
f86b512
b1c125a
6e687da
57a3258
926ec28
035b8f5
8901c43
0f31552
a4904af
bcb050c
01f497f
c8c9656
1ed419e
2b687ea
852aa33
bb527b5
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 |
|---|---|---|
| @@ -1 +1,14 @@ | ||
| function dedupe() {} | ||
| function dedupe(arr) { | ||
| const elements = []; | ||
| for (const item of arr) { | ||
| if (!elements.includes(item)) { | ||
| elements.push(item); | ||
| } | ||
| } | ||
| if (elements.length === arr.length) { | ||
| return arr.slice(); | ||
| } | ||
| return elements; | ||
| } | ||
|
|
||
| module.exports = dedupe; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,13 +16,28 @@ E.g. dedupe([1, 2, 1]) returns [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.todo("given an empty array, it returns an empty array"); | ||
| test("given an empty array, it returns an empty array", function() { | ||
| console.log(dedupe) | ||
|
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 are you logging something here?
Author
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. Again I must have left it there by mistake. I deleted it now. |
||
| 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 non duplicate array, it returns a copy of the array", function () { | ||
| const array = [1, 2, 3]; | ||
| const result = dedupe(array); | ||
| expect(result).toEqual(array); | ||
| }); | ||
|
|
||
| // Given an array of strings or numbers | ||
| // When passed to the dedupe function | ||
| // When passed to the dedupe function | ||
| // Then it should return a new array with duplicates removed while preserving the | ||
| // first occurrence of each element from the original array. | ||
| test("given an array of strings or numbers, it returns the original occurrence of the array", function () { | ||
| const array = [1, "c", 2, 3, "d"]; | ||
| const result = dedupe(array); | ||
| expect(result).toEqual(array); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| function findMax(elements) { | ||
| let largestNum; | ||
| for (let i = 0; i < elements.length; i++) { | ||
| if (typeof elements[i] === "number") { | ||
| if (largestNum === undefined || elements[i] > largestNum) { | ||
| largestNum = elements[i]; | ||
| } | ||
| } | ||
| } | ||
| return largestNum; | ||
| } | ||
|
|
||
| module.exports = findMax; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,20 @@ | ||
| function sum(elements) { | ||
| let sum = 0; | ||
| let hasNumber = false; | ||
|
|
||
| for (let i = 0; i < elements.length; i++) { | ||
| if (typeof elements[i] === "number") { | ||
| sum += elements[i]; | ||
| hasNumber = true; | ||
| } | ||
| } | ||
| if (hasNumber === false && elements.length >0) { | ||
| return undefined; | ||
| } | ||
| return sum; | ||
| } | ||
|
|
||
| let numbers = ["c", "b", "hi", 1]; | ||
|
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. Is there a better place to put this test case?
Author
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. Yes. I forgot the remove this after I finished testing with it. I was rushing with my work and i forget to tidy up a few things. I know this isn't a good excuse. It is deleted now. |
||
| console.log(sum(numbers)); | ||
|
|
||
| module.exports = sum; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,3 +36,4 @@ test("searches for null", () => { | |
|
|
||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
| // test checked and passed. | ||
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.
Why do you need this if branch? What does it do?
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.
Hi @LonMcGregor Thanks for the review and feedback first of all.
I must have forgot to delete it when I finished working on this specific program. It is deleted now.