Question: const fs = require('fs'); const _ = require(lodash); process.stdin.resume(); process.stdin.setEncoding('utf-8'); let ws; let input = ''; process.stdin.on('data', inputStdin => input += inputStdin); process.stdin.on('end', () =>

 const fs = require('fs'); const _ = require("lodash"); process.stdin.resume(); process.stdin.setEncoding('utf-8'); letws; let input = ''; process.stdin.on('data', inputStdin => input += inputStdin); process.stdin.on('end',

const fs = require('fs');

const _ = require("lodash");

process.stdin.resume();

process.stdin.setEncoding('utf-8');

let ws;

let input = '';

process.stdin.on('data', inputStdin => input += inputStdin);

process.stdin.on('end', () => {

ws = fs.createWriteStream(process.env.OUTPUT_PATH);

input

.replace(/\s*$/, '') // trim

.split(' ')

.map(str => str.replace(/\s*$/, '')) // trim again

.filter(str => str.length > 1) // remove empty strings

.map(str => str.split(',')) // parse command and options

.map(([cmd, ...opts]) => { // call coresponding function

switch(cmd) {

case 'add':

return add(...opts);

case 'remove':

return remove(...opts);

case 'move':

return move(...opts);

case 'count':

return writeLine(count(...opts));

case 'print':

return print();

default:

return;

}

});

ws.end();

});

// helper for printing new lines to correct write stream

function writeLine(str) {

ws.write(str + " ");

}

let orgChart;

/**

* @param {String} employeeId

* @param {String} name

* @param {String} managerId

*/

function add(employeeId, name, managerId) {

// implement me

}

/**

* @param {String} employeeId

* @param {String} newManagerId

*/

function move(employeeId, newManagerId) {

// implement me

}

/**

* Return the count, don't worry about writing the value to console

* @param {String} employeeId

* @returns {Int} number of employees that report up to a given employee

*/

function count(employeeId) {

// implement me

}

/**

* @param {String} employeeId

*/

function remove(employeeId) {

// implement me

}

/**

* Call writeLine(str) to print a single line

*/

function print() {

writeLine('implement me');

};

This is a program to manage the Organizational Structure in a company. The program should allow us to: 1. Add employees 2. Generate the Org Chart in a specific format (explained further below). 3. Remove employees 4. Move an Employee from one manager to another. 5. Count the number of employees that ultimately report up to a given manager. The input for this program is a text file comprising of a series of commands and parameters that may look like this: 6 add, 10, Sharilyn Gruber,-1 add, 7, Denice Mattice, 10 add, 3, Lawana Futrell,-1 add, 34, Lissette Gorney,7 add,5,Lan Puls,3 print ,, If an employee with an id has been added, then subsequent additions of employees with the same id are ignored. If an employee's manager has not already been added, then the employee is considered to have no manager. Adding an Employee: The command is of the format add, ,, If an employee with an id has been added, then subsequent additions of employees with the same id are ignored. If an employee's manager has not already been added, then the employee is considered to have no manager. Moving an Employee: The command is of the format move,, If an employee of that id does not exist, then do nothing. If an employee with the new manager id does not exist, then do nothing. The newly moved employee will be appended to the manager's list of reports, when the org chart is printed. Subsequent adds will continue to be added to the end of the list of reports. Removing an Employee: The command is of the format remove, If an employee of that id does not exist, then do nothing. After removal, if the employee had any reports, they should now report to the removed employee's manager. These employees will show up in the same order as they did under their former manager, but after any current reports of the new hanager. If the removed employee had no manager, then the reports will have no manager either. Counting Employees: The command is of the format count, This should return the total number of reports, including any indirect reports (all descendant reports), that the specified employee has. The processing of the input file is already implemented. You only have to implement the Add, Print, Remove, Move, and Count methods below. Feel free to add any other class members or other classes, as needed. Helpful Tips: 1. Some users have suggested that using the "vertical layout" mode (an option that you can select next to the language selection drop down box), is helpful as you can view the exercise description on the side while you build your solution, instead of having to repeatedly scroll up and down. 2. Note that some passing cases is better than no passing cases. Please keep this in mind if you are refining your code as time is running out. Changes you make to pass one additional case may break previously working code. If you run out of time, you solution will auto submit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!