Coder Social home page Coder Social logo

mini-coding-challenge's Introduction

Solution

This is the solution to the mini coding challenge

Node version used: v18.4.0

Libraries used: lodash

Todos

  1. Add test for individual functions.
  2. Find a way to better organize html metadata regex.

Mini Coding Challenge

Your challenge is to complete two utility functions and ensure their corresponding tests pass.

Steps

  1. Installation
  2. Implementation
  3. Submission

Installation

Do NOT fork this repo.

  1. Clone this repo (and cd into it)
  2. Install the dependencies using npm

Implementation

In ./src/ you'll find 2 JavaScript files (.js) and 2 test respective Jest test files (.test.js).

  1. get-metadata.js which exports getMetadata()
  2. filter-metadata.js which exports filterMetadata()

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.

get-metadata.js

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.

filter-metadata.js

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.

Tests

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

Submission

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:

  1. Create a new repository on GitHub.
  2. Remove the remote origin with: git remote rm origin
  3. Add the remote origin of your new repo with: git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPO-NAME.git
  4. Push your code to your new repo with: git push -u origin master (or main or whatever your preferred branch name is)

Linting/Formatting

mini-coding-challenge's People

Contributors

rudyzone avatar raooll avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.