-
-
Notifications
You must be signed in to change notification settings - Fork 269
Glasgow | 26-ITP-Jan| Martin McLean |Sprint 2|coursework #988
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
1604e30
c8a3d01
9cbe265
90a351e
3717525
f38855d
614e8cf
0504c63
1660c2a
fd6e951
3f3eb9b
f4bd70f
70d7954
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. What problems might arise if the quantity of ingredient changes later (e.g., to 100)? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| function contains() {} | ||
| function contains(inPut, content) { | ||
| try { | ||
| console.log(inPut.hasOwnProperty(content)); | ||
| return inPut.hasOwnProperty(content); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| } | ||
| console.log(contains({ a: 1, b: 2 }, "a")); | ||
| console.log(contains({}, 9)); | ||
| // console.log(contains([a, 1, b, 2], "a")); | ||
|
|
||
| module.exports = contains; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(countryAndCurrency) { | ||
| // const money = new Map(countryAndCurrency); | ||
| const cash = Object.fromEntries(countryAndCurrency); | ||
| // console.log(cash); | ||
| console.log(countryAndCurrency); | ||
| return cash; | ||
| } | ||
| createLookup([ | ||
| ["US", "USD"], | ||
| ["CA", "CAD"], | ||
| ]); | ||
|
|
||
| module.exports = createLookup; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "implement", | ||
| "description": "coureswork", | ||
| "devDependencies": { | ||
| "jest": "^30.2.0" | ||
| }, | ||
| "scripts": { | ||
| "test": "jest" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,24 @@ | ||
| function parseQueryString(queryString) { | ||
| const queryParams = {}; | ||
| if (queryString.length === 0) { | ||
| if (queryString === undefined || queryString.length === 0) { | ||
| return queryParams; | ||
| } | ||
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| const cutOff = pair.indexOf("="); | ||
| const key = pair.slice(0, cutOff); | ||
| const value = pair.slice(cutOff + 1, pair.length); | ||
| queryParams[key] = value; | ||
| console.log(key); | ||
| console.log(value); | ||
| } | ||
|
|
||
| return queryParams; | ||
| } | ||
| console.log(parseQueryString("y=8&r=y")); | ||
| console.log(parseQueryString("equation=x=y+1")); | ||
| console.log(parseQueryString("=")); | ||
| console.log(parseQueryString("abcdefghijk")); | ||
|
|
||
| module.exports = parseQueryString; |
|
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. some edge cases need to be considered
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 have made changes to the test for more edge cases, now i need to fix the code to pass the tests |
|
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. function tally(arr) has use console.log
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. removed |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,25 @@ | ||
| function tally() {} | ||
| function tally(arr) { | ||
| check = arr.constructor === Array; | ||
| try { | ||
| if (check !== true) { | ||
| throw new Error("input requires an array"); | ||
| } | ||
|
|
||
| let count = {}; | ||
| for (let letters of arr) { | ||
| if (count[letters]) { | ||
| count[letters]++; | ||
| } else { | ||
| count[letters] = 1; | ||
| } | ||
| } | ||
|
|
||
| console.log(arr); | ||
| return count; | ||
| } catch (e) { | ||
| return e.message; | ||
| } | ||
| } | ||
|
|
||
| console.log(tally({ 6: 7 })); | ||
| module.exports = tally; |
|
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 test expect(tally(["a", "b", "a"])).toEqual({ a: 2, b: 1 }); twice?
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. removed |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,16 +19,59 @@ const tally = require("./tally.js"); | |
| // Given a function called tally | ||
| // When passed an array of items | ||
| // Then it should return an object containing the count for each unique item | ||
| test("tally on an empty array returns an empty object", () => { | ||
| expect(tally(["apples", "bananas", "apples", "orange", "bananas"])).toEqual({ | ||
| apples: 2, | ||
| bananas: 2, | ||
| orange: 1, | ||
| }); | ||
| expect(tally(["ants", "bear", "ants", "antalope"])).toEqual({ | ||
| ants: 2, | ||
| bear: 1, | ||
| antalope: 1, | ||
| }); | ||
| expect(tally([4, 4, 3, 2, 2, 2, 2, "cat"])).toEqual({ | ||
| 4: 2, | ||
| 3: 1, | ||
| 2: 4, | ||
| cat: 1, | ||
| }); | ||
| }); | ||
|
|
||
| // Given an empty array | ||
| // When passed to tally | ||
| // Then it should return an empty object | ||
| test.todo("tally on an empty array returns an empty object"); | ||
| test("tally on an empty array returns an empty object", () => { | ||
| expect(tally([])).toEqual({}); | ||
| }); | ||
|
|
||
| // Given an array with duplicate items | ||
| // When passed to tally | ||
| // Then it should return counts for each unique item | ||
| test("tally it should return counts for each unique item", () => { | ||
| expect(tally(["armadillos", "boa_constrictor", "armadillos"])).toEqual({ | ||
| armadillos: 2, | ||
| boa_constrictor: 1, | ||
| }); | ||
| expect(tally(["ants", "bear", "ants", "antalope"])).toEqual({ | ||
| ants: 2, | ||
| bear: 1, | ||
| antalope: 1, | ||
| }); | ||
| expect(tally([4, 4, 3, 2, 2, 2, 2, "cat"])).toEqual({ | ||
| 4: 2, | ||
| 3: 1, | ||
| 2: 4, | ||
| cat: 1, | ||
| }); | ||
| }); | ||
|
|
||
| // Given an invalid input like a string | ||
| // When passed to tally | ||
|
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. The last test was not finished.
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. finnised now |
||
| // Then it should throw an error | ||
| test("When given an input other than an array", () => { | ||
| expect(tally("feet")).toBe("input requires an array"); | ||
| expect(tally(67)).toBe("input requires an array"); | ||
| expect(tally(true)).toBe("input requires an array"); | ||
| expect(tally({ 3: 4 })).toBe("input requires an array"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| const invert = require("../interpret/invert.js"); | ||
|
|
||
| test("test for a number followed by a letter", () => { | ||
| expect(invert({ 1: "a", 2: "b", 3: "c" })).toEqual({ | ||
| a: "1", | ||
| b: "2", | ||
| c: "3", | ||
| }); | ||
| }); | ||
| // expect(tally([])).toEqual({}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Title here</title> | ||
| <script defer src="quotes.js"></script> | ||
| </head> | ||
| <body onload="pickNewQuoteToDisplay()"> | ||
| <h1>hello there</h1> | ||
| <p id="quote"></p> | ||
| <p id="author"></p> | ||
| <button type="button" class="button" id="new-quote">New quote</button> | ||
| </body> | ||
| </html> |
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 does not meet the purpose of the question.
The goal of the program is to output the values of all properties in the object.
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 have changed this so it only logs the values now