Git Product home page Git Product logo

nodejs-intro-pset's Introduction

NodeJS Intro

Problem 1

Make a math module that imports and works the following way:

const math = require('./math.js');

math.add(1, 2);
math.subtract(5, 3);
math.divide(3, 3);
math.multiply(5, 5);

Problem 2

Make an ImageService module that takes in a JPG image from the root directory and makes a new copy in the specified directory and renamed to the new name.

const ImageService = require('./services/image.js');

ImageService.copyJPGTo('logo.jpg','newFolder', 'newName');

/*
  This will create a new folder called: newFolder/
  And inside here there will be a copy of the image called:
  newFolder/newName.jpg
*/

Problem 3

Make a module that stores the following users into a text database.

app.js

const UserService = require('./services/user');

const users = [
  {name: 'John', age: 30},
  {name: 'Bob', age: 23},
  {name: 'Emily', age: 40},
  {name: 'Michelle', age: 24},
  {name: 'Chris', age: 25}
];

UserService.save(users);

This should store the users in a text database format as follows:

users.txt

John,30
Bob,23
Emily,40
Michelle,24
Chris,25

Problem 4

Using the same module file. Make a new function that takes in a user.txt file.

user.txt

John,30
Bob,23
Emily,40
Michelle,24
Chris,25
Robert,28
Mike,27
Sarah,22

And returns the following:

app.js

const users = UserService.load('users.txt');

console.log(users);
/*
[
  {name: 'John', age: 30},
  {name: 'Bob', age: 23},
  {name: 'Emily', age: 40},
  {name: 'Michelle', age: 24},
  {name: 'Chris', age: 25},
  {name: 'Robert', age: 28},
  {name: 'Mike', age: 27},
  {name: 'Sarah', age: 22},
]
*/

nodejs-intro-pset's People

Contributors

mmosayed avatar

Watchers

James Cloos 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.