generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 273
Manchester | 26-ITP-Jan | Liban Jama | Sprint 2 | Data Groups #1050
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
Open
libanj0161
wants to merge
12
commits into
CodeYourFuture:main
Choose a base branch
from
libanj0161:Data-Groups-Sprint-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8eb514b
Completed sprint-2- implement
libanj0161 cf24d94
Completed Sprint2-debug
libanj0161 8e13b9e
Completed Interpret
libanj0161 faa6d1b
Completed interpret
libanj0161 f48667a
amended after pr comments
libanj0161 8dc6d67
Merge branch 'main' into Data-Groups-Sprint-2
libanj0161 3680a9c
fixed as per pr comments
libanj0161 a0e7c95
removed .only
libanj0161 8ff0784
Updated tally.js as per pr request
libanj0161 0d29926
Added a rejection for null and array, and added test as per pr comment
libanj0161 821b353
made contains work with map
libanj0161 fe9e5cc
updated
libanj0161 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,9 @@ | ||
| function contains() {} | ||
| function contains(object, propertyName) { | ||
| if (typeof object !== "object" || object === null || Array.isArray(object)) { | ||
| // if user passes something that is not an object, or object is null/array, then return false. | ||
| return false; | ||
| } | ||
| return Object.hasOwn(object, propertyName); | ||
| } | ||
|
|
||
| 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,19 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(list) { | ||
| // key = country code e.g. 'US' | ||
| // value = currency code e.g. 'USD' | ||
| // input = array of [country, currency] | ||
| // process = go through each pair, add to object | ||
| // output = object { country: currency } | ||
|
|
||
| // declare a variable and store empty object | ||
| // loop through the array | ||
| // while in the loop take each item and add it to the object | ||
| let items = {}; | ||
|
|
||
| for (let i = 0; i < list.length; i++) { | ||
| items[list[i][0]] = list[i][1]; | ||
| } | ||
| return items; | ||
| } | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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,16 @@ | ||
| function tally() {} | ||
| function tally(items) { | ||
| if (!Array.isArray(items)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| const plainObject = Object.create(null); | ||
|
|
||
| const itemsObject = items.reduce((acc, item) => { | ||
| acc[item] = (acc[item] || 0) + 1; | ||
| return acc; | ||
| }, plainObject); | ||
|
|
||
| return itemsObject; | ||
| } | ||
|
|
||
| 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,16 @@ | ||
| const invert = require("../interpret/invert"); | ||
|
|
||
| test(`Should return {"10": "x", "20": "y"} when given { x: 10, y: 20 } `, () => { | ||
| expect(invert({ x: 10, y: 20 })).toEqual({ 10: "x", 20: "y" }); | ||
| }); | ||
|
|
||
| test(`Should return {"2": "bounce", "100": "high"} when given { bounce: 2, high: 100 } `, () => { | ||
| expect(invert({ bounce: 2, high: 100 })).toEqual({ | ||
| 2: "bounce", | ||
| 100: "high", | ||
| }); | ||
| }); | ||
|
|
||
| test(`Should return {"foot": "ball"} when given { "ball": "foot" } `, () => { | ||
| expect(invert({ ball: "foot" })).toEqual({ foot: "ball" }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.