generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 147
WESTMIDLANDS|MAY-2025|SARA TAHIR|Sprint 2/coursework #565
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
SaraTahir28
wants to merge
11
commits into
CodeYourFuture:main
Choose a base branch
from
SaraTahir28:Sprint-2/Coursework
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.
+4,657
−30
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7feb9f9
Fixed the code, wrote my explanation.
SaraTahir28 efe91a5
Wrote my prediction and updated function to print out all property va…
SaraTahir28 47ece2c
Wrote the function. Discussed 2 methods to update the function.
SaraTahir28 d9248ca
Wrote tests and updated function to pass tests.
SaraTahir28 d169bf8
Wrote tests and updated the function to return an object.
SaraTahir28 f105fb6
Added several edge cases and updates query string function to pass al…
SaraTahir28 f91ae9b
wrote test cases and tally function.
SaraTahir28 0003a16
Answered a
SaraTahir28 c81574a
fixed the function, working properly now.
SaraTahir28 47e39e6
Answered all questions. Wrote tests and ran them with jest.
SaraTahir28 5c4a4e8
Changed after review.
SaraTahir28 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,16 @@ | ||
function contains() {} | ||
function contains(object, propertyName) { | ||
// Check if the input is a real object (not null or an array) | ||
const isObject = | ||
typeof object === "object" && object !== null && !Array.isArray(object); | ||
|
||
// If it's not a valid object or property name is missing, return false | ||
if (!isObject || typeof propertyName !== "string") { | ||
return false; | ||
} | ||
|
||
// Return true if the object has the property directly (not inherited) | ||
return object.hasOwnProperty(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,25 @@ | ||
function createLookup() { | ||
// implementation here | ||
function createLookup(pairs) { | ||
const lookup = {}; | ||
for (let i = 0; i < pairs.length; i++) { | ||
const [country, currency] = pairs[i]; | ||
lookup[country] = currency; | ||
} | ||
return lookup; | ||
} | ||
|
||
module.exports = createLookup; | ||
|
||
/*const pair = [['US','USD'],['CA','CAD']] | ||
const firstpair = pair[0] | ||
let country1 = firstpair[0] | ||
let currency1 = firstpair[1] | ||
console.log("First country:", country1); // US | ||
console.log("First currency:", currency1); | ||
|
||
const secondPair= pair[1] | ||
let country2 = secondPair[0] | ||
let currency2 = secondPair[1] | ||
console.log("Second country:", country2); // CA | ||
console.log("Second currency:", currency2); | ||
} | ||
*/ |
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,16 +1,49 @@ | ||
|
||
function parseQueryString(queryString) { | ||
const queryParams = {}; | ||
if (queryString.length === 0) { | ||
return queryParams; | ||
|
||
|
||
if (queryString.startsWith("?")) { // Remove "?" if present at start | ||
queryString = queryString.substring(1); | ||
} | ||
|
||
/*if (queryString.length === 0) { | ||
return queryParams; | ||
}*/ | ||
|
||
const keyValuePairs = queryString.split("&"); | ||
|
||
for (const pair of keyValuePairs) { | ||
const [key, value] = pair.split("="); | ||
queryParams[key] = value; | ||
if (!pair) continue; // Skip empty strings from && or trailing &, | ||
|
||
const idx = pair.indexOf("="); | ||
|
||
let rawKey, rawValue; | ||
|
||
if (idx === -1) { | ||
rawKey = pair; | ||
rawValue = ""; | ||
} else { | ||
rawKey = pair.slice(0, idx);// starts at zero, stop just before the index of = | ||
rawValue = pair.slice(idx + 1); | ||
} | ||
|
||
// Decode without replacing '+' with space | ||
const key = decodeURIComponent(rawKey); | ||
const value = decodeURIComponent(rawValue); | ||
|
||
if (queryParams.hasOwnProperty(key)) { | ||
if (Array.isArray(queryParams[key])) { | ||
queryParams[key].push(value); | ||
} else { | ||
queryParams[key] = [queryParams[key], value]; | ||
} | ||
} else { | ||
queryParams[key] = value; | ||
} | ||
} | ||
|
||
return queryParams; | ||
} | ||
|
||
module.exports = parseQueryString; |
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,21 @@ | ||
function tally() {} | ||
function tally(items) { | ||
if (!Array.isArray(items)) { | ||
throw new Error("Input should be an array"); | ||
} | ||
|
||
const result = {}; | ||
|
||
for (const item of items) { | ||
if (result[item]) { | ||
result[item]++; | ||
} else { | ||
result[item] = 1; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
module.exports = tally; | ||
//takes and array of items | ||
//item are keys | ||
// how many times that item is repeated in the array- count of that item(key) is the value of each key |
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,17 @@ | ||
const invert = require("./invert"); | ||
|
||
test("given an object of key-value, it should return inverted value-key", () => { | ||
expect(invert({ a: 1, b: 2 })).toEqual({ "1": "a", "2": "b" }); | ||
}); | ||
|
||
test("given an object of single key-value, it should return single value-key", () => { | ||
expect(invert({ a: 1 })).toEqual({ "1": "a" }); | ||
}); | ||
|
||
test("given an empty input it should return an empty object", () => { | ||
expect(invert({})).toEqual({}); | ||
}); | ||
|
||
test("invert values that are strings", () => { | ||
expect(invert({ a: "1", b: "pink" })).toEqual({ "1": "a", "pink": "b" }); | ||
}); |
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.
This isn't a major problem here, but remember in a more complex git project not to commit lots of comments of unused code like this.
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.
Noted, I will make sure I dont make it a practice.