@@ -9,20 +9,52 @@ const employees = [
99 [ 'Frank' , 'Engineering' , 110000 , 8 ] ,
1010 [ 'Grace' , 'Marketing' , 90000 , 6 ]
1111] ;
12- 1312console . log ( `Original list of employees:` ) ;
1413console . table ( employees ) ;
1514
16- // 1. getHighSalaryEmployees(minSalary)
15+ // 1 - getHighSalaryEmployees(minSalary)
1716
1817function getHighSalaryEmployees ( minSalary ) {
1918 let salary = employees
2019 . filter ( ( employee ) => employee [ 2 ] > minSalary )
2120 . map ( ( employee ) => `${ employee [ 0 ] } ($${ employee [ 2 ] } )` ) ;
22- console . log ( `List of employees with salary bigger than ${ minSalary } $` ) ;
21+ console . log ( `List of employees with salary bigger than ${ minSalary } $: ` ) ;
2322console . log ( salary ) ;
2423return salary ;
2524}
26- 2725getHighSalaryEmployees ( 80000 ) ;
2826
27+ // 2 - calculateTotalSalaryByDepartment()
28+ 29+ function calculateAllDepartmentsTotalSalary ( employees ) {
30+ console . log ( `Total salary expenditure for each department:` ) ;
31+ const departments = employees . reduce ( ( acc , employee ) => {
32+ if ( ! acc . includes ( employee [ 1 ] ) ) {
33+ acc . push ( employee [ 1 ] ) ;
34+ }
35+ return acc ;
36+ } , [ ] ) ;
37+ const result = departments . map ( department => {
38+ const departmentEmployees = employees . filter ( employee => employee [ 1 ] === department ) ;
39+ const totalSalary = departmentEmployees . reduce ( ( acc , employee ) => acc + employee [ 2 ] , 0 ) ;
40+ return [ department , totalSalary ] ;
41+ } ) ;
42+ return result ;
43+ }
44+ console . log ( calculateAllDepartmentsTotalSalary ( employees ) ) ;
45+ 46+ // 3 - getSeniorEmployees()
47+ 48+ function getSeniorEmployees ( ) {
49+ console . log ( 'Names and departments of all employees with 5+ years of experience:' ) ;
50+ const seniorEmployees = employees
51+ . filter ( employee => employee [ 3 ] >= 5 )
52+ . map ( employee => `${ employee [ 0 ] } (${ employee [ 1 ] } )` )
53+ . sort ( ) ;
54+ 55+ return seniorEmployees ;
56+ }
57+ 58+ console . log ( getSeniorEmployees ( ) ) ;
59+ // Očekivani izlaz: ['Alice (Engineering)', 'Charlie (Engineering)', 'Diana (Marketing)', 'Frank (Engineering)', 'Grace (Marketing)', 'Jane Doe (Sales)']
60+ // Primijeti da 'Jane Doe' iz mog originalnog niza također ima 6 godina iskustva i uvrštena je.
0 commit comments