-
-
Notifications
You must be signed in to change notification settings - Fork 197
London | 25-ITP-Sept | Gislaine Della Bella | Sprint 2 | Sprint 2 -Final #933
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
4938239
0d9e98c
b647f3a
6cdb275
8ad77a6
95f9e07
2ece854
9285ca4
96d1d84
d7ce32b
f110f2c
3c56ceb
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,13 @@ | ||
| function dedupe() {} | ||
| function dedupe(arr) { | ||
| const result = []; | ||
| for (const item of arr) { | ||
| if (!result.includes(item)) { | ||
| result.push(item); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| console.log(dedupe(["a", "a", "a", "b", "b", "c"])); | ||
|
|
||
| module.exports = dedupe; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| function findMax(elements) { | ||
| function findMax(numbersList) { | ||
| let onlyNumbers = numbersList.filter((item) => typeof item === "number"); | ||
| let currentMax = Math.max(...onlyNumbers); | ||
| return currentMax; | ||
| } | ||
|
|
||
| console.log(findMax([1, "apple", 5, 0, "banana", 3])); | ||
|
|
||
| module.exports = findMax; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,20 @@ | ||
| function sum(elements) { | ||
| function sum(theArray) { | ||
| const onlyNumbers = theArray.filter((item) => typeof item === "number"); | ||
| const theFinalSum = onlyNumbers.reduce((runningTotal, currentNumber) => { | ||
| return runningTotal + currentNumber; | ||
| }, 0); | ||
| return theFinalSum; | ||
| } | ||
|
|
||
| console.log(sum(["hey", 10, "hi", 60, 10])); | ||
|
|
||
| module.exports = sum; | ||
|
|
||
| //numbersList.filter((item) => typeof item === "number"); | ||
| /* Sum the numbers in an array | ||
|
|
||
| In this kata, you will need to implement a function that sums the numerical elements of an array | ||
|
|
||
| E.g. sum([10, 20, 30]), target output: 60 | ||
| E.g. sum(['hey', 10, 'hi', 60, 10]), target output: 80 (ignore any non-numerical elements) | ||
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,11 @@ | ||
| function contains() {} | ||
| function contains(someObject, propertyName) { | ||
| let whatTheRobotFound = someObject[propertyName]; | ||
| if (someObject[propertyName] === undefined) { | ||
|
Member
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. We can store the value contains({"name": undefined}, "name");
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. I see...my code returns false even if the property exists but is set to undefined. I’ll use the in operator to fix this so it checks for the property instead of its value |
||
| return false; | ||
|
Member
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. You should never have to write: if (something) {
return true;
} else {
return false;
}Because the condition in an return something;which does the same. If you need to negate it, you can return !something; |
||
| } else { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| module.exports = contains; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,16 +20,39 @@ as the object doesn't contains a key of 'c' | |
| // Given an empty object | ||
| // When passed to contains | ||
| // Then it should return false | ||
| test.todo("contains on empty object returns false"); | ||
| test("contains on empty object returns false", () => { | ||
| const inputEmpty = []; | ||
|
Member
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. This isn't an empty object, it's an array. It may be interesting to test what happens when passed an array, but it's not quite what the test name describes.
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. I used the symbol for an array [] by mistake. I’ll change it to {} |
||
| const result = contains(inputEmpty); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| // Given an object with properties | ||
| // When passed to contains with an existing property name | ||
| // Then it should return true | ||
| test("Given an object with properties when pass to contains it returns true", () => { | ||
| const myObject = { | ||
| name: "Alice", | ||
| age: 30, | ||
| city: "London", | ||
| }; | ||
| const result = contains(myObject, "name"); | ||
| expect(result).toEqual(true); | ||
| }); | ||
|
|
||
| // Given an object with properties | ||
| // When passed to contains with a non-existent property name | ||
| // Then it should return false | ||
| test("give a object with proprieties when pass contains with non-exist proprity name it should return false", () => { | ||
| const inputProprieties2 = ["f", "g", "h"]; | ||
| const result = contains(inputProprieties2); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
Comment on lines
+45
to
+49
Member
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. I'm not quite sure what this test description is trying to convey, or what the test is trying to test... Can you explain?
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. I meant to pass an object (like {a: 1}) and a property name to check if it exists. I error used an array instead |
||
|
|
||
| // Given invalid parameters like an array | ||
| // When passed to contains | ||
| // Then it should return false or throw an error | ||
| test("invalid parameters should return false or throw an error", () => { | ||
| const invalidParameters = ("f", "g", "h"); | ||
| const result = contains(invalidParameters); | ||
|
Comment on lines
+55
to
+56
Member
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. Not specifying a second parameter is an interesting case here, but the test name isn't very descriptive of this... Also, what is the type of
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. It is a string. Because I used () instead of square brackets, JavaScript only looks at the last item. I also forgot the second parameter. I’ll fix it to be a proper test |
||
| expect(result).toEqual(false); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(countryCurrencyPairs) { | ||
| const lookup = {}; | ||
|
|
||
| for (let i = 0; i < countryCurrencyPairs.length; i++) { | ||
| const countryCode = countryCurrencyPairs[i][0]; | ||
|
Comment on lines
+4
to
+5
Member
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. This works, but probably isn't the most clear way of iterating across this array. Can you think how other looping constructs, or destructuring, could help you make this more clear and easy to read?
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. i ffor...of loop would work better there. |
||
| const currencyCode = countryCurrencyPairs[i][1]; | ||
|
|
||
| lookup[countryCode] = currencyCode; | ||
| } | ||
|
|
||
| return lookup; | ||
| } | ||
|
|
||
| module.exports = createLookup; | ||
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.
What's this variable for?
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.
I realize now that I’m not actually using this variable, so I’ll remove it to keep the code clean.