Skip to content

About

Technical test: Filter data from a JSON file based on user input

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Javascript developer test

Filter

Your job is to write a command-line interface in Node.js. This program has to filter a list of elements containing a pattern.

Details:

  • In the following file src/data/data.js, there are Countries containing Peoples containing Animals.
  • Only animals containing ry are displayed. The order should be kept intact.
  • Empty array after filtering are NOT returned.

Sample of running the command, and its output:

$ node app.js --filter=ry
[
  {
    name: 'Uzuzozne',
    people: [
      {
        name: 'Lillie Abbott',
        animals: [
          {
            name: 'John Dory'
          }
        ]
      }
    ]
  },
  {
    name: 'Satanwi',
    people: [
      {
        name: 'Anthony Bruno',
        animals: [
          {
            name: 'Oryx'
          }
        ]
      }
    ]
  }
]

Count

The next goal is to print the counts of People and Animals by counting the number of children and appending it in the name, eg. Satanwi [2].

Sample of running the command, and its output:

node app.js --count
[ { name: 'Dillauti [5]',
    people:
     [ { name: 'Winifred Graham [6]',
         animals:
          [ { name: 'Anoa' },
            { name: 'Duck' },
            { name: 'Narwhal' },
            { name: 'Badger' },
            { name: 'Cobra' },
            { name: 'Crow' } ] },
       { name: 'Blanche Viciani [8]',
         animals:
          [ { name: 'Barbet' },
            { name: 'Rhea' },
            { name: 'Snakes' },
            { name: 'Antelope' },
            { name: 'Echidna' },
            { name: 'Crow' },
            { name: 'Guinea Fowl' },
            { name: 'Deer Mouse' } ] },
      ...
...
]

Requirements

  • The code must be available in a GIT repository
  • No library/modules should be used, except for the testing library

Appreciation

We will be really attentive to:

  • Code readability, structure and consistency
  • Tests, and how they are written

Build and Run

Before starting, install the packages

npm install

As we're using TypeScript in the project, you will need to build the project.

npm run build

This will compile the TypeScript source files into JavaScript in the dist/ directory.

Running the Application

To run the application:

node dist/app.js [--filter=pattern] [--count]

Example:

  • To filter animals by the pattern ry:

    node dist/app.js --filter=ry
  • To count:

    node dist/app.js --count

You can also pass multiple parameters at the same time:

node dist/app.js --filter=ry --count

Alternatively, you can use npm scripts:

  • Filtering:

    npm start -- --filter=ry
  • Counting:

    npm start -- --count
  • Multiple params:

    npm start -- --filter=ry --count

About

Technical test: Filter data from a JSON file based on user input

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages