From a166f0d8386cea6da40599286e050c5cdb6e1dcb Mon Sep 17 00:00:00 2001 From: ali bavarsad Date: Thu, 9 Dec 2021 00:42:25 +0000 Subject: [PATCH 1/3] 1-writers --- mandatory/1-writers.js | 78 ++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/mandatory/1-writers.js b/mandatory/1-writers.js index f815c156..2f3ac651 100644 --- a/mandatory/1-writers.js +++ b/mandatory/1-writers.js @@ -55,7 +55,7 @@ let writers = [ occupation: "writer", age: 49, alive: true, - } + }, ]; /* @@ -68,7 +68,12 @@ Exercise 1: */ function logAllWriters() { // write your code to log all writers here -}; + writers.forEach((writer) => + console.log( + `Hi, my name is ${writer.firstName} ${writer.lastName}. I am ${writer.age} years old, and work as a ${writer.occupation}.` + ) + ); +} /* Exercise 2: @@ -81,6 +86,15 @@ Exercise 2: function logDeadWritersInTheirForties() { // write your code here + const person = writers.filter( + (element) => + element.age >= 40 && element.age <= 49 && element.alive === false + ); + person.forEach((element) => + console.log( + `Writer ${element.firstName} ${element.lastName} died at ${element.age} years old.` + ) + ); } /* @@ -93,6 +107,15 @@ Exercise 3: function logAliveWritersInTheirForties() { // write your code here + const person = writers.filter( + (element) => + element.age >= 40 && element.age <= 49 && element.alive === true + ); + person.forEach((element) => + console.log( + `Hi, my name is ${element.firstName} ${element.lastName}. I am ${element.age} years old.` + ) + ); } /* ======= TESTS - DO NOT MODIFY ===== @@ -101,29 +124,32 @@ function logAliveWritersInTheirForties() { - (Reminder: You must have run `npm install` one time before this will work!) */ -test("exercise 1", () => expectFunctionToLog(logAllWriters, [ - "Hi, my name is Virginia Woolf. I am 59 years old, and work as a writer.", - "Hi, my name is Zadie Smith. I am 40 years old, and work as a writer.", - "Hi, my name is Jane Austen. I am 41 years old, and work as a writer.", - "Hi, my name is Bell Hooks. I am 63 years old, and work as a writer.", - "Hi, my name is Yukiko Motoya. I am 49 years old, and work as a writer." -])); - -test("exercise 2", () => expectFunctionToLog(logDeadWritersInTheirForties, [ - "Writer Jane Austen died at 41 years old." -])); - -test("exercise 3", () => expectFunctionToLog(logAliveWritersInTheirForties, [ - "Hi, my name is Zadie Smith. I am 40 years old.", - "Hi, my name is Yukiko Motoya. I am 49 years old." -])); +test("exercise 1", () => + expectFunctionToLog(logAllWriters, [ + "Hi, my name is Virginia Woolf. I am 59 years old, and work as a writer.", + "Hi, my name is Zadie Smith. I am 40 years old, and work as a writer.", + "Hi, my name is Jane Austen. I am 41 years old, and work as a writer.", + "Hi, my name is Bell Hooks. I am 63 years old, and work as a writer.", + "Hi, my name is Yukiko Motoya. I am 49 years old, and work as a writer.", + ])); + +test("exercise 2", () => + expectFunctionToLog(logDeadWritersInTheirForties, [ + "Writer Jane Austen died at 41 years old.", + ])); + +test("exercise 3", () => + expectFunctionToLog(logAliveWritersInTheirForties, [ + "Hi, my name is Zadie Smith. I am 40 years old.", + "Hi, my name is Yukiko Motoya. I am 49 years old.", + ])); function expectFunctionToLog(f, values) { - const consoleLogSpy = jest.spyOn(console, 'log'); - f(); - expect(consoleLogSpy).toBeCalledTimes(values.length); - values.forEach((value, i) => { - expect(consoleLogSpy).nthCalledWith(i+1, value); - }); - consoleLogSpy.mockRestore(); -}; \ No newline at end of file + const consoleLogSpy = jest.spyOn(console, "log"); + f(); + expect(consoleLogSpy).toBeCalledTimes(values.length); + values.forEach((value, i) => { + expect(consoleLogSpy).nthCalledWith(i + 1, value); + }); + consoleLogSpy.mockRestore(); +} From 65788d1c6a3cc5e33f23c41fbfd83f278d4dc6f1 Mon Sep 17 00:00:00 2001 From: ali bavarsad Date: Thu, 9 Dec 2021 00:51:40 +0000 Subject: [PATCH 2/3] 2- eligible students --- mandatory/2-eligible-students.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mandatory/2-eligible-students.js b/mandatory/2-eligible-students.js index cb472063..94421f5b 100644 --- a/mandatory/2-eligible-students.js +++ b/mandatory/2-eligible-students.js @@ -20,7 +20,8 @@ */ function eligibleStudents(attendances) { - + const enoughAttendances = attendances.filter(person => person.attendance >= 8); + return enoughAttendances.map(person => person.name); } /* ======= TESTS - DO NOT MODIFY ===== From b6ed17e157cda7b8b492db0635dfbbde5718e14d Mon Sep 17 00:00:00 2001 From: ali bavarsad Date: Thu, 9 Dec 2021 01:56:03 +0000 Subject: [PATCH 3/3] 3- journey planner --- mandatory/3-journey-planner.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/mandatory/3-journey-planner.js b/mandatory/3-journey-planner.js index 2a96b8a2..89852116 100644 --- a/mandatory/3-journey-planner.js +++ b/mandatory/3-journey-planner.js @@ -27,7 +27,13 @@ */ function journeyPlanner(locations, transportMode) { - + const availableLocations = []; + for (const key in locations) { + if (locations[key].includes(transportMode)) { + availableLocations.push(key); + } + } + return availableLocations; } /* ======= TESTS - DO NOT MODIFY ===== @@ -36,10 +42,10 @@ function journeyPlanner(locations, transportMode) { - (Reminder: You must have run `npm install` one time before this will work!) */ const londonLocations = { - "Angel": ["tube", "bus"], - "London Bridge": ["tube", "river boat"], - "Tower Bridge": ["tube", "bus"], - "Greenwich": ["bus", "river boat"], + Angel: ["tube", "bus"], + "London Bridge": ["tube", "river boat"], + "Tower Bridge": ["tube", "bus"], + Greenwich: ["bus", "river boat"], }; test("journeyPlanner function works - case 1", () => { @@ -62,5 +68,5 @@ test("journeyPlanner function works - case 3", () => { "Angel", "London Bridge", "Tower Bridge", - ]) -}); \ No newline at end of file + ]); +});