Ultimate Kronos Group | Microsoft Teams Technical Panel | Java Output Junior Employees

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-08-15Added By Anonymous
Source: Link

I was asked to review this block of code and to see if I can spot anything wrong with it, and to suggest improvements. Also, you cannot make any changes to the fake database, and only look at the Java functions. Can anyone tell me what they were looking for ?

1// !!!!! NOTE: Use-case: we need to display all junior employees names, comma separated 2// !!!!! NOTE: The output from this code should be "Andrea,Steve," 3function main() { 4 5 var list = ''; 6 var service = getEmployeeService(); 7 8 list = service.getAllEmployees(); 9 10 //This gets Junior employees 11 getJuniorEmployees(list); 12 //outputs them 13 outputEmployeesToConsole(list); 14 15 function getEmployeeService() { 16 return { 17 getAllEmployees: function() { 18 // !!!!! NOTE: assume this is calling real back-end service that grabs data form DB 19 return callBackEnd_getAllEmployees(); 20 } 21 }; 22 } 23} 24 25//Calling main function 26main(); 27 28 29function callBackEnd_getAllEmployees() { 30 return allCompanyEmployees; 31} 32 33function getJuniorEmployees(list) { 34 var empl = []; 35 for (var i=0; i<list.length; i++) { 36 if (list[i].years_of_service < 7) { 37 empl.push(list[i]); 38 } 39 } 40 list = empl; 41} 42 43function outputEmployeesToConsole(list) { 44 var str = null; 45 for (var i=0; i<list.length; i++) { 46 str = list[i].name + ','; 47 } 48 console.log(str); 49} 50 51// !!!!! NOTE: assume this is coming form a DB table. Assume fields' names and values are like in below JSON 52var allCompanyEmployees = [ 53 {id: 1, name: 'Andrea', age: 32, department: 'R&D', active: true, years_of_service: 6}, 54 {id: 2, name: 'John', age: 42, department: 'QA', active: false, years_of_service: 14}, 55 {id: 3, name: 'Steve', age: 22, department: 'MANAGEMENT', active: true, years_of_service: 1} 56];


Comments