-
-
Notifications
You must be signed in to change notification settings - Fork 145
feat: add a prototype for the Guild Loot Tracker lab #1078
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 5 commits
7da31bd
c2ca3e7
fba7edb
492458a
d790e41
d510dcb
b59a232
789a19f
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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| const guild = { | ||
| nemo: { | ||
| gold: 31, | ||
| silver: 48, | ||
| reputation: 9, | ||
| experience: 198, | ||
| }, | ||
| shamin: { | ||
| gold: 78, | ||
| silver: 64, | ||
| reputation: 12, | ||
| experience: 111, | ||
| }, | ||
| ahlerich: { | ||
| gold: 41, | ||
| silver: 7, | ||
| reputation: 7, | ||
| experience: 70, | ||
| }, | ||
| corlandus: { | ||
| gold: 81, | ||
| silver: 2, | ||
| reputation: 20, | ||
| experience: 220, | ||
| }, | ||
| pedro: { | ||
| gold: 34, | ||
| silver: 28, | ||
| reputation: 10, | ||
| experience: 179, | ||
| }, | ||
| morgat: { | ||
| gold: 36, | ||
| silver: 81, | ||
| reputation: 12, | ||
| experience: 82, | ||
| }, | ||
| }; | ||
|
|
||
| function cloneGuildData(object) { | ||
| return { ...object }; | ||
| } | ||
|
|
||
| function addLootEntry(object, entry) { | ||
| const memberData = ["gold", "silver", "reputation", "experience"]; | ||
|
|
||
| if ( | ||
| !Object.keys(entry).includes("member") || | ||
| typeof entry["member"] !== "string" | ||
| ) { | ||
| return 'Entry must include a "member" key, with a "string" value (the guild member name).'; | ||
| } | ||
|
|
||
| for (const value of memberData) { | ||
| if ( | ||
| !Object.keys(entry).includes(value) || | ||
| typeof entry[value] !== "number" | ||
| ) { | ||
| return `Entry must include a "${value}" key, with a "number" value.`; | ||
| } | ||
| } | ||
|
|
||
| const clonedGuildData = cloneGuildData(object); | ||
| const { member } = entry; | ||
| const { gold, silver, reputation, experience } = entry; | ||
|
|
||
| clonedGuildData[member] = { gold, silver, reputation, experience }; | ||
|
|
||
| return clonedGuildData; | ||
| } | ||
|
|
||
| function getMemberTotals(object, member) { | ||
| if (!Object.keys(object).includes(member)) { | ||
| return `"${ingredient}" not found in the guild roster.`; | ||
| } else { | ||
| return `${member}'s totals - gold: ${Object.values(object[member])[0]}, silver: ${Object.values(object[member])[1]} reputation: ${Object.values(object[member])[2]}, experience: ${Object.values(object[member])[3]}`; | ||
| } | ||
| } | ||
|
|
||
| function listTopMembers(object, key, limit) { | ||
| const membersSortedByValue = Object.entries(object); | ||
| let returnObject = {}; | ||
|
|
||
| membersSortedByValue.sort((a, b) => b[1][key] - a[1][key]); | ||
| for (let member of membersSortedByValue.slice(0, limit)) { | ||
| returnObject[member[0]] = member[1]; | ||
| } | ||
| return returnObject; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| In this lab, you will aggregate resource totals per guild member inside nested objects. | ||
|
|
||
| **Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. | ||
|
|
||
| **User Stories:** | ||
|
|
||
| 1. You should accept meal entries shaped like `{ member, gold, silver, reputation, experience }`. | ||
jdwilkin4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 2. You should implement `addLootEntry(object, entry)` that clones and updates cumulative resources per member. | ||
| 3. You should implement `getMemberTotals(object, member)` with guard clauses for unknown members. | ||
| 4. You should implement `listTopMembers(object, key, limit)` that sorts descending by a specific resource type (e.g., finding the member with the most `gold`). | ||
| 5. You should implement `cloneGuildData(object)` to protect against accidental mutations. | ||
jdwilkin4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Note: Use `Object.keys`, `Object.values`, and `Object.entries`. Include tests for aggregation accuracy and cloning behavior. | ||
|
Contributor
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. Is this just a note for yourself? Or part of the user stories?
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 copied the current user stories from the original issue - the contribution guide mentions the additions of notes/tips, so I included the note from them as well. Since I've only contributed to some quiz questions before, trying to match the initial requirements as close as I could seemed safer than rewriting them (i hope that makes at least some sense). Thank you, I'll go over the other labs in this part of the curriculum and try to make the user stories more descriptive and uniform with those. |
||
Uh oh!
There was an error while loading. Please reload this page.