From a6d6f2096224917cca7bd172020ba2f4621cee4d Mon Sep 17 00:00:00 2001 From: Moayad Mohammed Date: Sat, 27 Apr 2024 12:55:20 +0200 Subject: [PATCH 1/5] Traffic Light Prep completed --- .DS_Store | Bin 6148 -> 6148 bytes Week2/.DS_Store | Bin 0 -> 6148 bytes Week2/prep-exercises/.DS_Store | Bin 0 -> 6148 bytes .../1-traffic-light/traffic-light.js | 2 ++ 4 files changed, 2 insertions(+) create mode 100644 Week2/.DS_Store create mode 100644 Week2/prep-exercises/.DS_Store diff --git a/.DS_Store b/.DS_Store index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..1e79288e1333d0e6149661949ab44330c8e22abc 100644 GIT binary patch literal 6148 zcmeHK&2G~`5S~rb)}cbm0i+&^WQl8961S>aaWNr1aNtrSdH@t`Y^7FRyNVrhh$8u1 z-ho%(%9HReoZy??t+4ZRMNsWTv)}IQ%-H)SJDVjU(Vv7pqBap(P{!s1G%JMXS(l`t zEjvIVa}<=nO0rKuk_AiN#$XsQ4E$>h@ZQ}bpK^R6s_$Pe3NN4szof`l-=j--rxemY z#lU?X8`B7*Yvf2d3+yABz$1j^0QRs_7dY>?g}f~~r!zclK(B!-BE*x0h)udc?uf3a zSI;fJtoID2`Hikl--DYZ&WmpMhiGgxH@CK}ZEMH+;9X`@ukedW-uK7vc=RUAlHjiI z2XEtOI&43BnWcpvr_opj#9;)N_ZM**X48H)NyA*mdTPRIS*>AvcQ$j5dmY<3J(+jx z*{Rd**hh!Q^Lfj9{PfxL^Wjx;oo2Uqdx$_qmGV&I9q{TZYya$x(GHFi>TH>w^tt zbTyU=W$8d8uK>U%%u>+ji{1K2en8q;hR~h&XXBguZ delta 66 zcmZoMXfc=|#>AjHu~2NHo+1YW5HK<@2y7PQ5M$Y_z%h$?Gdl-A2T%b}u84%9H(hI5x+KtY8KJ$3PAT diff --git a/Week2/.DS_Store b/Week2/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3f7e8b53404cad4f6bb8096a7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sjy*}612K5I4f2+G27wZoq& jFziu`SU!q3p;qA6Yyd-#wL^FyauKjJNFfaTRR(?lzHn}n literal 0 HcmV?d00001 diff --git a/Week2/prep-exercises/1-traffic-light/traffic-light.js b/Week2/prep-exercises/1-traffic-light/traffic-light.js index f4a5c1a..ed33470 100644 --- a/Week2/prep-exercises/1-traffic-light/traffic-light.js +++ b/Week2/prep-exercises/1-traffic-light/traffic-light.js @@ -9,6 +9,7 @@ function getCurrentState(trafficLight) { // TODO // Should return the current state (i.e. colour) of the `trafficLight` // object passed as a parameter. + return trafficLight.possibleStates[trafficLight.stateIndex]; } function getNextStateIndex(trafficLight) { @@ -17,6 +18,7 @@ function getNextStateIndex(trafficLight) { // - if the color is green, it will turn to orange // - if the color is orange, it will turn to red // - if the color is red, it will turn to green + return (trafficLight.stateIndex+1)%trafficLight.possibleStates.length; } // This function loops for the number of seconds specified by the `secs` From f62c357473914a3d6acc9dd066bc66bd84b01138 Mon Sep 17 00:00:00 2001 From: Moayad Mohammed Date: Sat, 27 Apr 2024 14:13:28 +0200 Subject: [PATCH 2/5] Submitted Prep Exercice 2 --- Week2/prep-exercises/2-experiments/index.js | 15 +++++++++++++- Week2/prep-exercises/2-experiments/test.js | 22 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 Week2/prep-exercises/2-experiments/test.js diff --git a/Week2/prep-exercises/2-experiments/index.js b/Week2/prep-exercises/2-experiments/index.js index 7e5aa92..ab91fac 100644 --- a/Week2/prep-exercises/2-experiments/index.js +++ b/Week2/prep-exercises/2-experiments/index.js @@ -12,6 +12,10 @@ function runExperiment(sampleSize) { // value from the previous step. Use the first element of `valueCounts` // for keeping a count how many times the value 1 is thrown, the second // element for value 2, etc. + for(let i = 0 ; i < sampleSize; i++){ + const x =Math.floor(Math.random()*(6-1+1)+1); //x is the random number + valueCounts[x-1]++; + } const results = []; @@ -24,7 +28,10 @@ function runExperiment(sampleSize) { // 2. Convert the computed percentage to a number string with a precision of // two decimals, e.g. '14.60'. // 3. Then push that string onto the `results` array. - + for(let i of valueCounts){ + let percentage = ((i/sampleSize)*100).toFixed(2); + results.push(percentage); + } return results; } @@ -36,6 +43,12 @@ function main() { // value of the `sampleSizes` array. // Log the results of each experiment as well as the experiment size to the // console. + + for(let sampleSize of sampleSizes){ + let experimentResutls = runExperiment(sampleSize); + console.log(experimentResutls, " ", sampleSize); + } + // The expected output could look like this: // // [ '26.00', '17.00', '10.00', '19.00', '16.00', '12.00' ] 100 diff --git a/Week2/prep-exercises/2-experiments/test.js b/Week2/prep-exercises/2-experiments/test.js new file mode 100644 index 0000000..fc6ef4e --- /dev/null +++ b/Week2/prep-exercises/2-experiments/test.js @@ -0,0 +1,22 @@ +let x = []; +for (i=0;i<20; i++){ + let y = Math.floor(Math.random()*6+1); + x.push(y); +} + console.log("🚀 ~ x:", x) + + +// const valueCounts = [0, 0, 0, 0, 0, 0]; +// const sampleSize = 100000; + +// for(let i = 0 ; i < sampleSize; i++){ +// const x =Math.floor(Math.random()*(6-1+1)+1); //x is the random number +// valueCounts[x-1]++; +// } +// const results = []; +// for(let i of valueCounts){ +// let percentage = ((i/sampleSize)*100).toFixed(2); +// results.push(percentage); +// } +// console.log("🚀 ~ results:", results) + From 06e2138118b864c44053f0a5de71395307d309f6 Mon Sep 17 00:00:00 2001 From: Moayad Mohammed Date: Sat, 4 May 2024 14:02:06 +0200 Subject: [PATCH 3/5] Submitting prep exercise --- .DS_Store | Bin 6148 -> 8196 bytes Week2/.DS_Store | Bin 6148 -> 6148 bytes Week2/prep-exercises/.DS_Store | Bin 6148 -> 8196 bytes .../1-hyf-program/1-find-mentors.js | 14 ++++++++------ .../1-hyf-program/2-class-list.js | 18 +++++++++++++++++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.DS_Store b/.DS_Store index 1e79288e1333d0e6149661949ab44330c8e22abc..3c1d4e210b2d9f96c022df45ce068868aa8f7ad8 100644 GIT binary patch delta 179 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMA$hR?IH}hr%jz7$c**Q2SHn1@A zP3B?QY0S@1!jQ^P3?vnRWHLh$LncE3kXOv0$B@NP?3t6FoRpKF1TqSU*8}mq$pY-6 zo6oa^F)q+?Wc6l2j_=Hq`9(Y@`}1&cFhX3# KusNP*4l@7-ASHtU delta 115 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jH4hU^g=(_hcS{os)G1xi|9( zhB8g|7m=S>dU!EA2ZtatP%#h)a03ZfkiLzD-b3D%+W&ob4 B6MO&w diff --git a/Week2/.DS_Store b/Week2/.DS_Store index 3f7e8b53404cad4f6bb8096a7a259214534b04fc..b4a38926bca0283dfe679397d08afbb2c067c30f 100644 GIT binary patch delta 155 zcmZoMXfc=|#>B!ku~2NHo+2aH#(>?7i&&T#xi<4K6)_6rq#Fh&=jRqMfPwYo$#zT% zBDwi4E=f80NkB1B)qu~2NHo+2aL#(>?7jBJ~ESc(`oyRjW)+}Ln}X)`+qKL=3FWf zw@krx9q*1hLM2kLN(dBWARD8=092hlIgwdW)q%U%v=)OK(;F=d^Rs+{?0s^U&L{; SJC6VdBP8e;HplbKVFmz|a$7tA delta 130 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGjUEV6q~50$jGuWU^gQp%VYyVrOA2%(Twbq zyMQFeBw^pl%t9F(%W_y2vvY6=G6VGhfdDs=Ok LEVenGXAUy}w+a+= diff --git a/Week3/prep-exercises/1-hyf-program/1-find-mentors.js b/Week3/prep-exercises/1-hyf-program/1-find-mentors.js index 72baa61..3257582 100644 --- a/Week3/prep-exercises/1-hyf-program/1-find-mentors.js +++ b/Week3/prep-exercises/1-hyf-program/1-find-mentors.js @@ -8,10 +8,11 @@ import { modules, students, mentors, classes } from "./hyf.js"; * ['John', 'Mary'] */ const possibleMentorsForModule = (moduleName) => { - // TODO complete this function + return mentors.filter((mentor) => + mentor.canTeach.includes(moduleName)) + .map((mentor) => mentor.name) }; -// You can uncomment out this line to try your function -// console.log(possibleMentorsForModule('using-apis')); +console.log(possibleMentorsForModule('using-apis')); /** * Tjebbe wants to make it even easier for himself. @@ -20,7 +21,8 @@ const possibleMentorsForModule = (moduleName) => { * It should return a single name. */ const findMentorForModule = (moduleName) => { - // TODO complete this function + const possibleMentors = possibleMentorsForModule(moduleName) + const randomNumber = Math.floor(Math.random()*possibleMentors.length) + return possibleMentors[randomNumber] }; -// You can uncomment out this line to try your function -// console.log(findMentorForModule('javascript')); +console.log(findMentorForModule('javascript')); diff --git a/Week3/prep-exercises/1-hyf-program/2-class-list.js b/Week3/prep-exercises/1-hyf-program/2-class-list.js index 44d2798..25c01dd 100644 --- a/Week3/prep-exercises/1-hyf-program/2-class-list.js +++ b/Week3/prep-exercises/1-hyf-program/2-class-list.js @@ -13,7 +13,16 @@ import { modules, students, mentors, classes } from "./hyf.js"; */ const getPeopleOfClass = (className) => { // TODO complete this function + const activeClass = classes.find((a) => a.name === className); + const studentsOfClass = students.filter((student) => student.class.includes(className)) + const mentorOfClass = mentors.filter((mentor) => mentor.nowTeaching?.includes(activeClass.currentModule)) + const peopleOfClass = [ + ...studentsOfClass.map((student) => ({name: student.name, role: "Student"})), + ...mentorOfClass.map((mentor) => ({name: mentor.name, Role: "Mentor"})) + ] +return peopleOfClass }; + // You can uncomment out this line to try your function // console.log(getPeopleOfClass('class34')); @@ -31,6 +40,13 @@ const getPeopleOfClass = (className) => { */ const getActiveClasses = () => { // TODO complete this function + const activeClasses = classes.filter((c) => c.active === true) + const classInfo ={} + for (let i of activeClasses){ + const participants = getPeopleOfClass(i.name); + classInfo[i.name] = participants; + } + return classInfo }; // You can uncomment out this line to try your function -// console.log(getActiveClasses()); + console.log(getActiveClasses()); From a8fb9a906a0f401305743b305a5434ca439b4735 Mon Sep 17 00:00:00 2001 From: Moayad Mohammed Date: Tue, 7 May 2024 11:38:57 +0200 Subject: [PATCH 4/5] Removing --- .gitignore | 3 ++ .../1-hyf-program/2-class-list.js | 17 ++++--- test scripts.js | 50 +++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 test scripts.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..56f4224 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +Week3/.DS_Store +Week3/prep-exercises/.DS_Store +.Rhistory diff --git a/Week3/prep-exercises/1-hyf-program/2-class-list.js b/Week3/prep-exercises/1-hyf-program/2-class-list.js index 25c01dd..f368823 100644 --- a/Week3/prep-exercises/1-hyf-program/2-class-list.js +++ b/Week3/prep-exercises/1-hyf-program/2-class-list.js @@ -12,7 +12,6 @@ import { modules, students, mentors, classes } from "./hyf.js"; * [{ name: 'John', role: 'student' }, { name: 'Mary', role: 'mentor' }] */ const getPeopleOfClass = (className) => { - // TODO complete this function const activeClass = classes.find((a) => a.name === className); const studentsOfClass = students.filter((student) => student.class.includes(className)) const mentorOfClass = mentors.filter((mentor) => mentor.nowTeaching?.includes(activeClass.currentModule)) @@ -24,7 +23,7 @@ return peopleOfClass }; // You can uncomment out this line to try your function -// console.log(getPeopleOfClass('class34')); +// console.log(getPeopleOfClass('class34')); /** * We would like to have a complete overview of the current active classes. @@ -39,13 +38,17 @@ return peopleOfClass * } */ const getActiveClasses = () => { - // TODO complete this function const activeClasses = classes.filter((c) => c.active === true) const classInfo ={} - for (let i of activeClasses){ - const participants = getPeopleOfClass(i.name); - classInfo[i.name] = participants; - } + // for (let i of activeClasses){ + // const participants = getPeopleOfClass(i.name); + // classInfo[i.name] = participants; + // } + + activeClasses.map((x)=> { + const participants = getPeopleOfClass(x.name); + classInfo[x.name] = participants + }) return classInfo }; // You can uncomment out this line to try your function diff --git a/test scripts.js b/test scripts.js new file mode 100644 index 0000000..559adc7 --- /dev/null +++ b/test scripts.js @@ -0,0 +1,50 @@ +const companies = [ + { + name: "Acme Corp", + ceo: { + name: "John Doe", + location: { city: "New York", country: "USA" }, + }, + }, + { + name: "Beta Ltd", + ceo: null, // No CEO for this company + }, + { + name: "Gamma Inc", + ceo: { name: "Jane Smith" }, // CEO without location information + }, + { + name: "Kojima Productions", + ceo: { + name: "Hideo Kojima", + location:{city: "Tokyo", country:"Japan"} + } + }, + ]; + + // Fix the function to safely retrieve the CEO's city or a default message + function getCeoCity(company) { + if (company.ceo) { + if (company.ceo.location) { + return company.ceo.location.city; + } else { + return "No city information available"; + } + } else { + return "No city information available"; + } + + // const city = company.ceo?.location?.city || "No city information available"; + // return city + + } + + + + console.log(getCeoCity(companies[0])); // Should output "New York" + console.log(getCeoCity(companies[1])); // Should output "No city information available" + console.log(getCeoCity(companies[2])); // Should output "No city information available" + console.log(getCeoCity(companies[3])); // Should output "No city information available" + + \ No newline at end of file From fd794577c76d44d21da957889f7f664cfcf7fe0c Mon Sep 17 00:00:00 2001 From: Moayad Mohammed Date: Fri, 10 May 2024 23:08:53 +0200 Subject: [PATCH 5/5] adding git ignore --- .DS_Store | Bin 8196 -> 8196 bytes .gitignore | 1 + 2 files changed, 1 insertion(+) diff --git a/.DS_Store b/.DS_Store index 3c1d4e210b2d9f96c022df45ce068868aa8f7ad8..c2757277e9898640cafa58e71793b3d1ec3573a6 100644 GIT binary patch delta 81 zcmZp1XmOa}&nU1lU^hRbz-AtSBo-b9R)%nfR3OY|Fq!NpbdlGjEVw8yCqFNpfq{W> WW8r$H&Fm82SSDW-@Sz1 delta 33 pcmZp1XmOa}&&aniU^hP_-)0_xB$my2JTsX$vrBwq*;v8O3;?v33Qhn3 diff --git a/.gitignore b/.gitignore index 56f4224..2a6a7f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ Week3/.DS_Store Week3/prep-exercises/.DS_Store .Rhistory +.DS_Store