Coder Social home page Coder Social logo

problemset's Introduction

The use of ES6 features especially Promises, Generators and Classes are highly encouraged. Using a transpiler/compiler will be optional but babeljs is recommended. The candidate should review his answers as this will assess the candidate's development style and adherence to best practices (readability, correctness and testability) in NodeJS.

Before starting the project, the candidate should fork this repository and apply his changes to that forked version accordingly (the link to this forked repository should be submitted). Commit messages should follow angularjs's commit message format.

Any third party npm modules may be used as long it is added as dependency in the package.json file.

Solutions to the programming challenges should be put on index.js.

Environment

  • NodeJS v5.7.1 or later

Library (lib.js)

  • asyncOp - Mocks an asynchronous IO operation. Accepts a value input which is printed before and after the asynchronous operation.
  • RandStream - Extends stream.Readable. Generates a stream of random characters from the following character set:
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.

1. Asynchronous Operations

Create a function doAsync which accepts an array arr as input. Each element in the array can be either of type String or [String].

Example Input

[
  'A',
  [ 'B', 'C', 'D', 'E' ],
  'F',
  'G',
  [ 'H', 'I' ]
]

doAsync should apply asyncOp for all elements in arr. Each application of asyncOp should be either executed in series or parallel with each other depending on how they are arranged. If the elements are bundled together in an array, then asyncOp will be applied in parallel.

Example Usage
let input = [
  'A',
  [ 'B', 'C' ],
  'D'
]

doAsync(input);
Example Output
START: A
FINISH: A
START: B
START: C
FINISH: C
FINISH: B
START: D
FINISH: D

2. Streams

Create a class RandStringSource which accepts an instance of the class RandStream as input. RandStringSource should be a subclass of events.EventEmitter.

Given the stream of random characters generated by RandStream, RandStringSource should emit an event data whenever a string enclosed by . is detected. The enclosed string should be used as payload in the data event.

Example Usage
let source = new RandStringSource(new RandStream());

source.on('data', (data) => {
  console.log(data);
})
Example Output
CHUNK: gh82Ad.AJK092shLKmb
gh82Ad
AJK092shLKmblkg
CHUNK: lkg.6294fjsk.5..642ksLMMD0g
lkg
6294fjsk
5
642ksLMMD0g
CHUNK: kms.zenoan.
kms
zenoan

3. Resource Pooling

Create a class ResourceManager which accepts an integer count as input. ResourceManager should manage a limited number of resource objects. The maximum number of resource objects that can be created is determined by count.

ResourceManager should implement a function borrow which accepts a callback as parameter. The borrow function should reserve a resource object and pass it to the caller through the callback. A resource object can never be acquired by other borrowers until the release function in the resource object is called.

Example Usage
let pool = new ResourceManager(2);
console.log('START');

let timestamp = Date.now();

pool.borrow((res) => {
  console.log('RES: 1');

  setTimeout(() => {
    res.release();
  }, 500);
});

pool.borrow((res) => {
  console.log('RES: 2');
});

pool.borrow((res) => {
  console.log('RES: 3');
  console.log('DURATION: ' + (Date.now() - timestamp));
});
Example Output
START
RES: 1
RES: 2
RES: 3
DURATION: 514

problemset's People

Contributors

rogermadjos avatar kugtong33 avatar ginamostugnos 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.