Giter Site home page Giter Site logo

tech-lead-technical-test's Introduction

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 data.js, there are Countries containing Peoples containing Animals.
  • Only animals containing the pattern passed as argument (e.g. 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

Candidate notes

  • I chose to favor array functions (.map, .filter) over more performant for-loops for code clarity. Had there been an extra level of nesting or a larger set of data, I would not have made the same choice. If interested, it shows in my solutions to the advent of code through the years (less and less one-liners, more and more for loops)
  • I also used the .reduce function to parse arguments. This is a function I tend to avoid for code clarity, or to use with mutation (e.g. .reduce((acc, curr) => { acc[curr.key] = curr.value); return acc }, {}) rather than .reduce((acc, curr) => ({ ...acc, [curr.key]: curr.value }), {}))
  • The spec did not tell if --filter and --count could be used in conjunction. I took the liberty to make it possible (e.g. node app.js --count --filter=ry)

tech-lead-technical-test's People

Contributors

uptip 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.