File tree Expand file tree Collapse file tree 1 file changed +9
-14
lines changed
Sprint-1/destructuring/exercise-2 Expand file tree Collapse file tree 1 file changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -73,26 +73,21 @@ let hogwarts = [
7373
7474//task 1
7575function getGryffindorMembers ( arr ) {
76- let gryffindorMembers = [ ] ;
77- arr . forEach ( ( { firstName, lastName, house } ) => {
78- if ( house === "Gryffindor" ) {
79- gryffindorMembers . push ( `${ firstName } ${ lastName } ` ) ;
80- }
81- } ) ;
82- console . log ( gryffindorMembers . join ( '\n' ) ) ;
76+ const gryffindorMembers = arr . filter ( ( { house } ) => house === "Gryffindor" ) . map ( ( { firstName, lastName } ) => `${ firstName } ${ lastName } ` ) . join ( '\n' ) ;
77+
78+ console . log ( gryffindorMembers ) ;
8379}
8480
8581getGryffindorMembers ( hogwarts ) ;
8682
8783//task 2
8884function getTeachersWithPets ( arr ) {
89- let teachersWithPets = [ ] ;
90- arr . forEach ( ( { firstName, lastName, occupation, pet } ) => {
91- if ( occupation === "Teacher" && pet ) {
92- teachersWithPets . push ( `${ firstName } ${ lastName } ` ) ;
93- }
94- } ) ;
95- console . log ( teachersWithPets . join ( '\n' ) ) ;
85+ const teachersWithPets = arr . filter ( ( { occupation, pet } ) => occupation === "Teacher" && pet ) . map ( ( { firstName, lastName } ) =>
86+ `${ firstName } ${ lastName } `
87+ ) . join ( '\n' ) ;
88+
89+
90+ console . log ( teachersWithPets ) ;
9691}
9792
9893getTeachersWithPets ( hogwarts ) ;
You can’t perform that action at this time.
0 commit comments