generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 211
Manchester| ITP-25-SEP | Fithi Teklom| Sprint 2 | Coursework #898
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
Closed
Fithi-Teklom
wants to merge
17
commits into
CodeYourFuture:main
from
Fithi-Teklom:coursework-sprint-2
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
020a638
used a dot notation
Fithi-Teklom 00d78e4
predicted and explained
Fithi-Teklom 106c8d5
changed it to for in loop
Fithi-Teklom 7246481
modified author.js
Fithi-Teklom f31c786
predicted nad fixed recipe.js
Fithi-Teklom 85c361c
tested my tests
Fithi-Teklom d8bb643
made some adjustments for the contains.test.js
Fithi-Teklom 9547061
done lookup.test.js
Fithi-Teklom 89482b0
tally.test.js is done
Fithi-Teklom 1903cda
created a test file for invert.js
Fithi-Teklom 57a0316
modified count-words.js
Fithi-Teklom 23fc493
added a test file to the till.js
Fithi-Teklom d0281fd
test file has passed for till.js
Fithi-Teklom 6d3cd1a
modified querystring.js
Fithi-Teklom f3cafed
adjusted recipe.js
Fithi-Teklom d67e338
the querystring can now handle url decoder
Fithi-Teklom be4358d
fixed tally.js
Fithi-Teklom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| function contains() {} | ||
| function contains(obj, key) { | ||
|
|
||
| if(typeof obj !== "object" || obj === null || Array.isArray(obj)){ | ||
| return false; | ||
| } | ||
|
|
||
| return obj.hasOwnProperty(key); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| module.exports = contains; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| function createLookup() { | ||
| function createLookup(pairs) { | ||
| // implementation here | ||
| const lookup = {}; | ||
| for(const [countryCode, currencyCode]of pairs){ | ||
| lookup[countryCode] = currencyCode; | ||
| } | ||
| return lookup; | ||
| } | ||
|
|
||
| module.exports = createLookup; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,20 @@ | ||
| function tally() {} | ||
| function tally(items) { | ||
| if (!Array.isArray(items)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| const result = Object.create(null);; | ||
|
|
||
| for (const item of items) { | ||
| if (result[item]) { | ||
| result[item] += 1; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
|
|
||
| } | ||
|
|
||
| module.exports = tally; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| const invert = require("./invert"); | ||
|
|
||
| test("inverts a simple object", () => { | ||
| expect(invert({ a: 1 })).toEqual({ "1": "a" }); | ||
| }); | ||
|
|
||
| test("inverts multiple key/value pairs", () => { | ||
| expect(invert({ a: 1, b: 2 })).toEqual({ "1": "a", "2": "b" }); | ||
| }); | ||
|
|
||
| test("inverts string values", () => { | ||
| expect(invert({ x: "apple", y: "banana" })).toEqual({ | ||
| apple: "x", | ||
| banana: "y" | ||
| }); | ||
| }); | ||
|
|
||
| test("throws an error when input is not an object", () => { | ||
| expect(() => invert("not an object")).toThrow("Input must be a non-null object"); | ||
| }); | ||
|
|
||
| test("throws an error for null", () => { | ||
| expect(() => invert(null)).toThrow("Input must be a non-null object"); | ||
| }); | ||
|
|
||
| test("throws an error for arrays", () => { | ||
| expect(() => invert([1, 2, 3])).toThrow("Input must be a non-null object"); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Arrays are objects in JavaScript, and they do have property names -- just not the same ones as objects.
Which keys do arrays have, and how does that affect how reliable your test is?
When testing whether the function handles arrays properly, try using a key that an array might
realistically contain. Otherwise, you might get a passing test even if the function isn't checking for arrays at all.
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.
okay, i get it.