-
-
Notifications
You must be signed in to change notification settings - Fork 279
Sheffield | 26-Jan-ITP | Martha Ogunbiyi| Sprint 2| Coursework/sprint 2 #1133
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 14 commits
36332cf
a706aa1
57572df
c84f128
7beca08
52babe2
96d9df2
3a2ddf7
3a6e6f9
42a2aae
fb46c74
f0e1410
08d64f9
4a6e24e
85d62d3
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,3 +1,13 @@ | ||
| function contains() {} | ||
| function contains(obj, targetKey) { | ||
| if ( | ||
| obj === null || | ||
| typeof obj !== "object" || | ||
| Array.isArray(obj) || | ||
| Object.getPrototypeOf(obj) !== Object.prototype | ||
|
||
| ) { | ||
| throw new Error("Invalid Parameter"); | ||
| } | ||
| return Object.hasOwn(obj, targetKey); | ||
| } | ||
|
|
||
| module.exports = contains; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(codeCurrencyArrays) { | ||
| const result = {}; | ||
|
|
||
| for (const [code, currency] of codeCurrencyArrays) { | ||
| result[code] = currency; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| module.exports = createLookup; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,15 @@ | ||
| function tally() {} | ||
| function tally(list) { | ||
| if (!Array.isArray(list)) { | ||
| throw new Error("Invalid Parameter"); | ||
| } | ||
|
|
||
| const uniqueItems = Object.create(null); | ||
|
|
||
| for (const item of list) { | ||
| uniqueItems[item] = (uniqueItems[item] || 0) + 1; | ||
| } | ||
|
|
||
| return uniqueItems; | ||
| } | ||
|
|
||
| module.exports = tally; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| const invert = require("./invert.js"); | ||
|
|
||
| //Given a function invert() | ||
| //When passed an object | ||
| //Then it should return a swapped key and value in the object | ||
| // example: Given => {a: 1, b: 2, c: 3}, should return {1: a, 2: b, 3: c} | ||
|
|
||
| test("Given an object with at least one key value pair, it should return an inverted key value", () => { | ||
| const input = { a: 1, b: 2, c: 3 }; | ||
| const output = invert(input); | ||
| const target = { "1": "a", "2": "b", "3": "c" }; | ||
| expect(output).toEqual(target); | ||
| }) |
Uh oh!
There was an error while loading. Please reload this page.