GithubHelp home page GithubHelp logo

mwa-homework02-nodejs01's Introduction

MWA Homework 02

Written Exercises

  1. Explain why do we want sometimes to use setImmediate instead of using setTimeout?
  2. Explain the difference between process.nextTick and setImmediate?
  3. Name 10 core modules that Node provides by default, and 10 of the Global objects?

Exercise 02

Given the node application code within the exercise02 folder, install all the dependencies with npm i command, and run the application with npm run start command.

Note how the get_data() method within the data.ts file returns the following response body:

interface Todo { "userId": number, "id": number, "title": string, "completed": boolean }

const response_body = [
  { "userId": 1, "id": 1, "title": "delectus", "completed": false },
  { "userId": 1, "id": 2, "title": "quis officia", "completed": false },
  { "userId": 2, "id": 3, "title": "suscipit incidunt", "completed": false }
  // ...
]

Complete the code in format.ts and convert the response asynchronously into an object grouping the Todo items by userId, as follows:

const desired_response = {
    1 : [
      { "id": 1, "title": "delectus", "completed": false}, 
      { "id": 2, "title": "quis officia", "completed": false}
    ],
    2 : [
      { "id": 3, "title": "suscipit incidunt", "completed": false }
    ]
  // ...
}

The conversion allows for improving the time complexity of finding all Todo items for a specific user from O(n) to O(1).

Create a new markdown file solution02.md and explain in detail the performance implications of your solution on the node process.

mwa-homework02-nodejs01's People

Contributors

asaadsaad avatar

Stargazers

 avatar

Watchers

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