Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var _ = require('underscore');
- // function sayHello() {
- // console.log('Hello, World');
- // }
- // _.times(5, sayHello);
- // -- Start -- //
- const employees_input = [
- '1,Richard,Engineering',
- '2,Erlich,HR',
- '3,Monica,Business',
- '4,Dinesh,Engineering',
- '6,Carla,Engineering',
- '9,Laurie,Directors'
- ];
- const friendships_input = [
- '1,2',
- '1,3',
- '1,6',
- '2,4'
- ];
- const expected_output = {
- 1: [2,3,6],
- 2: [1, 4],
- 3: [1],
- 4: [2],
- 6: [1],
- 9: [],
- };
- let final = {};
- for(let item of employees_input){
- item = item.split(',');
- final[item[0]] = [];
- }
- for(let connection of friendships_input){
- connection = connection.split(',');
- final[connection[0]].push(connection[1]);
- final[connection[1]].push(connection[0]);
- }
- // console.log(final);
- let final_two = {};
- for(let department of employees_input){
- department = department.split(',');
- department = department[2];
- if(final_two.hasOwnProperty(department) === false){
- final_two[department] = {'employees': 1, 'employees_with_outside_friends': 0};
- } else {
- final_two[department].employees += 1;
- }
- }
- for(let department in final_two){
- for(let employee of employees_input){
- employee = employee.split(',');
- if(employee[2] === department){
- for(let friend of employees_input){
- friend = friend.split(',');
- if(employee[2] !== friend[2]){
- if(final[employee[0]].includes(friend[0])){
- final_two[department]['employees_with_outside_friends'] += 1;
- }
- }
- }
- }
- }
- }
- console.log(final_two);
- const expected_output_2 = {
- 'Engineering':{
- 'employees':3,
- 'count_of_employees_with_friends_in_other_departments':2
- },
- 'HR':{
- 'employees':1,
- 'count_of_employees_with_friends_in_other_departments':1
- },
- 'Business':{'employees':1, 'employees_with_outside_friends':1},
- 'Directors':{'employees':1, 'employees_with_outside_friends':0}
- }
Add Comment
Please, Sign In to add comment