Overview
Scenario: You are working for a social media company that has just merged with another. You are tasked with creating a function that takes an undetermined amount of arrays of username and merges them into one larger array to keep track of all the users on your merged website. You will also want to create a date of merging and return that combined with the merged array as an object
Estimated Completion Time: 30-60 minutes
Tools and Resources
- Tools: Visual Studio Code (VSCode), Node.js
- Resources: MDN Web Docs
- Setup: Fork and clone the provided GitHub repository, and run
npm install
to set up the project locally.
Instructions
-
Fork and Clone the Repository:
- Go to the provided GitHub repository link.
- Fork the repository to your GitHub account.
- Clone the forked repository to your local machine.
- Open the project in VSCode.
- Run
npm install
to install all necessary dependencies.
-
Create a combineUsers function:
- Create a function named
combineUsers
and assign the following arguments:...args
(a rest argument) Containing an indeterminite amount of arraysargs
will take the form of an array of array- Each internal array are arrays of usernames (strings)
- Create a function named
-
Initialize return object
- Inside
combineUsers
define the variablecombinedObject
(object).- Initialize with a key of
users
with the value[]
- Initialize with a key of
- Inside
-
Loop through args
- Loop through args to isolate each array
-
Merge arrays
- Using a spread operator merge arrays together into the
users
attribute ofcombinedObject
- Using a spread operator merge arrays together into the
-
Get todays date
- Add an attribute to
combinedObject
calledmerge_date
and using datejs give it the current date- In datejs give it the format of
M/d/yyyy
- Don't forget to npm install and to add
require('datejs')
outside ofcombineUsers
(datejs is already in package.json)
- In datejs give it the format of
- Add an attribute to
-
Return object
- return
combinedObject
- return