-
-
Save davidm17p/5db9144abe463ab25d53185c52299bf1 to your computer and use it in GitHub Desktop.
This file contains 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
/* Instructions: If you get stuck write the portion out you can't complete in | |
pseudo code (try to still be specific about what you would do). Include a | |
question worded how you would ask another member of the development team | |
to gain the information needed to be able to complete the task. Code | |
should be commented. Include a commented section at the top with your name, | |
date of development, and purpose of script. | |
Add an object for yourself following a similar format. Put each object in | |
an array so you have an array of objects (your choice how to do that). | |
Iterate through the array of objects adding the date the script was run | |
to each object as favorite things may change in the future. Console.log | |
only active records with the Name, date, Favorite movie of each person. | |
Add a function that can sort the output by object property. There may | |
be a time where no Active records are found. Include code that provides | |
a message when that occurs. | |
*/ | |
// Question: Is there a possibility that we would need to add dynamically more fields? Should we prepare the code for that? | |
// Will we have different status than Active and Inactive in the future? | |
// Will this be run multiple times in the future? For what use case? | |
// Name: David Medrano | |
// Date of Development: 06/02/2025 | |
// Script Purpose: Filtering and enhancing objects of people and their preferences | |
let rockyObj = { | |
'Name': 'Rocky', | |
'Favorite Food': 'Sushi', | |
'Favorite Movie': 'Back to The Future', | |
'Status': 'Inactive' | |
} | |
let miroslavObj = { | |
'Name': 'Miroslav', | |
'Favorite Food': 'Sushi', | |
'Favorite Movie': 'American Psycho', | |
'Status': 'Active' | |
} | |
let donnyObj = { | |
'Name': 'Donny', | |
'Favorite Food': 'Singapore chow mei fun', | |
'Favorite Movie': 'The Princess Bride', | |
'Status': 'Inactive' | |
} | |
let mattObj = { | |
'Name': 'Matt', | |
'Favorite Food': 'Brisket Tacos', | |
'Favorite Movie': 'The Princess Bride', | |
'Status': 'Active' | |
} | |
let davidObj = { | |
'Name': 'David', | |
'Favorite Food': 'Burritos', | |
'Favorite Movie': 'Mission Impossible', | |
'Status': 'Active' | |
} | |
const peopleObjs = [rockyObj, miroslavObj, donnyObj, mattObj, davidObj]; | |
const newPeopleObjs = peopleObjs.map((p) => { | |
return { | |
...p, | |
date: new Date().toLocaleString() | |
} | |
}); | |
const logOutput = (peopleObjs, attribute) => { | |
let sortedPeopleObjs = [...peopleObjs]; | |
sortedPeopleObjs = sortedPeopleObjs.filter(p => p['Status'] === 'Active'); | |
if (!sortedPeopleObjs?.length) { | |
console.log("No active records found"); | |
return; | |
} | |
sortedPeopleObjs.sort((a, b) => a[attribute].localeCompare(b[attribute])); | |
for (const person of sortedPeopleObjs) { | |
console.log("Name: ", person['Name']); | |
console.log("Favorite Food: ", person['Favorite Food']); | |
console.log("Favorite Movie: ", person['Favorite Movie'], '\n'); | |
} | |
} | |
logOutput(newPeopleObjs, 'Favorite Food') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment