Your challenge is to complete two utility functions and ensure their corresponding tests pass.
Steps
Do NOT fork this repo.
- Clone this repo (and
cd
into it) - Install the dependencies using npm
In ./src/
you'll find 2 JavaScript files (.js
) and 2 test respective Jest test files (.test.js
).
get-metadata.js
which exportsgetMetadata()
filter-metadata.js
which exportsfilterMetadata()
Both files are assumed to be utility functions that are a part of a larger application.
The fictional web app deals primarily with these "Metadata" objects as its main data, structured like so:
type Metadata = {
url: string | null;
siteName: string | null;
title: string | null;
description: string | null;
keywords: string[] | null;
author: string | null;
};
Example:
const metadata = {
url: "https://www.example.com/something/to-test",
siteName: "Example Site Name",
title: "Example Title",
description: "Example description.",
keywords: ["example", "keywords"],
author: "Example Author",
};
Imagine that you have a server backend which is able to pull the HTML from a website at a specific URL. From there, it would be handed down to the getMetadata()
function, with the HTML passed (as a string) as the parameter.
For the getMetadata()
function, you'll need to parse the HTML to extract the important and relevant metadata information, including the URL, site name, title, description, keywords, and author. (Then you'll return the Metadata object.)
From there, imagine that the frontend web app has a list of these Metadata objects and a search input bar. That search bar will require you to finish the filterMetadata()
function, which it will use to filter the Metadata list based on a given search query.
In this file, you'll need to complete the getMetadata()
function. It's typings are:
function getMetadata(html: string): Metadata;
You are welcome to break this down however you'd like; however, please don't use any external libraries or packages for this file, such as JSDOM.
Please follow the instructions in the JSDoc comments above the function.
In this file, you'll need to complete the filterMetadata()
function. It's typings are:
function filterMetadata(metadata: Metadata[], query: string): Metadata[];
You are also welcome to break this down into multiple functions, and if you choose to or feel the need to, you can import any external libraries or packages you'd like. (Honestly, I don't think the challenge requires anything from npm, but please solve this in whatever way you believe is best.)
As before, please follow the instructions in the JSDoc comments above the function.
This challenge uses Jest for testing.
As you complete the implementation, please ensure that the Jest tests pass.
In the root project directory, you can run the following scripts:
npm test
Or, to keep an open watcher, run:
npm run test:watch
Once again, do NOT fork this repo.
When you're done and ready to submit your code in the application, follow these steps to push your code to your own GitHub repo:
- Create a new repository on GitHub.
- Remove the remote origin with:
git remote rm origin
- Add the remote origin of your new repo with:
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPO-NAME.git
- Push your code to your new repo with:
git push -u origin master
(ormain
or whatever your preferred branch name is)