Guest User

Untitled

a guest
Jul 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. var _ = require('underscore');
  2.  
  3. // function sayHello() {
  4. // console.log('Hello, World');
  5. // }
  6.  
  7. // _.times(5, sayHello);
  8.  
  9. // -- Start -- //
  10. const employees_input = [
  11. '1,Richard,Engineering',
  12. '2,Erlich,HR',
  13. '3,Monica,Business',
  14. '4,Dinesh,Engineering',
  15. '6,Carla,Engineering',
  16. '9,Laurie,Directors'
  17. ];
  18.  
  19. const friendships_input = [
  20. '1,2',
  21. '1,3',
  22. '1,6',
  23. '2,4'
  24. ];
  25.  
  26. const expected_output = {
  27. 1: [2,3,6],
  28. 2: [1, 4],
  29. 3: [1],
  30. 4: [2],
  31. 6: [1],
  32. 9: [],
  33. };
  34.  
  35. let final = {};
  36.  
  37. for(let item of employees_input){
  38. item = item.split(',');
  39. final[item[0]] = [];
  40. }
  41.  
  42.  
  43. for(let connection of friendships_input){
  44. connection = connection.split(',');
  45. final[connection[0]].push(connection[1]);
  46. final[connection[1]].push(connection[0]);
  47. }
  48.  
  49. // console.log(final);
  50.  
  51.  
  52. let final_two = {};
  53.  
  54. for(let department of employees_input){
  55. department = department.split(',');
  56. department = department[2];
  57. if(final_two.hasOwnProperty(department) === false){
  58. final_two[department] = {'employees': 1, 'employees_with_outside_friends': 0};
  59. } else {
  60. final_two[department].employees += 1;
  61. }
  62. }
  63.  
  64.  
  65. for(let department in final_two){
  66. for(let employee of employees_input){
  67. employee = employee.split(',');
  68. if(employee[2] === department){
  69. for(let friend of employees_input){
  70. friend = friend.split(',');
  71. if(employee[2] !== friend[2]){
  72. if(final[employee[0]].includes(friend[0])){
  73. final_two[department]['employees_with_outside_friends'] += 1;
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
  80.  
  81.  
  82.  
  83. console.log(final_two);
  84.  
  85. const expected_output_2 = {
  86. 'Engineering':{
  87. 'employees':3,
  88. 'count_of_employees_with_friends_in_other_departments':2
  89. },
  90. 'HR':{
  91. 'employees':1,
  92. 'count_of_employees_with_friends_in_other_departments':1
  93. },
  94. 'Business':{'employees':1, 'employees_with_outside_friends':1},
  95. 'Directors':{'employees':1, 'employees_with_outside_friends':0}
  96. }
Add Comment
Please, Sign In to add comment