-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
Draft
Sebastian-Wlo
wants to merge
14
commits into
freeCodeCamp:main
Choose a base branch
from
Sebastian-Wlo:lab-nutrient-tracker-dictionary
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.
Draft
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7da31bd
feat: add prototype for Nutrient Tracker Dictionary lab prototype
Sebastian-Wlo c2ca3e7
feat: add user-stories.md to the nutrient tracker prototype
Sebastian-Wlo fba7edb
chore: renamed "lab-nutrient-tracker-dictionary" directory
Sebastian-Wlo 492458a
docs: change "nutrient tracker" references in lab's "user-stories.md"
Sebastian-Wlo d790e41
refactor: rewrite of "nutrient tracker" functions
Sebastian-Wlo d510dcb
docs: changed the lab's summary section to be more descriptive
Sebastian-Wlo b59a232
refactor: change "listTopMembers" function to "listMembers"
Sebastian-Wlo 789a19f
docs: remove the "listTopMembers" mentions from "user-stories.md", ad…
Sebastian-Wlo 615c8a5
refactor: removed users stories for Guild Loot Tracker
Sebastian-Wlo c1777d2
refactor: restructured Guild Loot Tracker prototype
Sebastian-Wlo 686091e
chore: remove the "lab-" prefix from the prototype's directory name
Sebastian-Wlo 3b7695f
feat: add listMemberNames() function that introduces Object.keys() me…
Sebastian-Wlo cb705ae
refactor: rewrite getMemberTotal() to return an object or `false`
Sebastian-Wlo 77284da
refactor: rewrite 'listMembers', 'getMemberTotals', and 'addLootEntry…
Sebastian-Wlo 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
89 changes: 89 additions & 0 deletions
89
fullstack-cert/js-projects/lab-guild-loot-tracker/script.js
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,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; | ||
| } |
13 changes: 13 additions & 0 deletions
13
fullstack-cert/js-projects/lab-guild-loot-tracker/user-stories.md
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,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
|
||
| 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
|
||
|
|
||
| Note: Use `Object.keys`, `Object.values`, and `Object.entries`. Include tests for aggregation accuracy and cloning behavior. | ||
|
jdwilkin4 marked this conversation as resolved.
Outdated
|
||
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.