From 1b5342434fd265688bdd164df71496b0e744e796 Mon Sep 17 00:00:00 2001 From: MartinBoylan <63868146+MartinBoylan@users.noreply.github.com> Date: Fri, 19 Jun 2020 15:02:07 +0100 Subject: [PATCH 1/3] Week 1 JS Martin mandatory --- week-1/2-mandatory/.DS_Store | Bin 0 -> 6148 bytes week-1/2-mandatory/1-syntax-errors.js | 16 ++++++++++------ week-1/2-mandatory/2-logic-error.js | 9 +++++---- week-1/2-mandatory/3-function-output.js | 11 ++++++++++- week-1/2-mandatory/4-tax.js | 10 ++++++++-- 5 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 week-1/2-mandatory/.DS_Store diff --git a/week-1/2-mandatory/.DS_Store b/week-1/2-mandatory/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Fri, 26 Jun 2020 21:26:04 +0100 Subject: [PATCH 2/3] week 2 homework --- .DS_Store | Bin 6148 -> 6148 bytes week-1/.DS_Store | Bin 0 -> 6148 bytes week-1/1-exercises/.DS_Store | Bin 0 -> 6148 bytes week-2/.DS_Store | Bin 0 -> 6148 bytes week-2/1-exercises/.DS_Store | Bin 0 -> 6148 bytes .../B-boolean-literals/exercise.js | 3 + .../C-comparison-operators/exercise.js | 6 +- week-2/1-exercises/D-predicates/exercise.js | 4 +- week-2/1-exercises/E-conditionals/exercise.js | 6 +- .../F-logical-operators/exercise.js | 21 +++- .../F-logical-operators/exercise2.js | 17 +++- .../G-conditionals-2/exercise-1.js | 4 +- .../G-conditionals-2/exercise-2.js | 4 +- .../G-conditionals-2/exercise-3.js | 11 ++- .../G-conditionals-2/exercise-4.js | 3 + .../1-exercises/H-array-literals/exercise.js | 4 +- .../I-array-properties/exercise.js | 5 +- .../1-exercises/J-array-get-set/exercise.js | 4 +- .../1-exercises/J-array-get-set/exercises2.js | 3 +- week-2/2-mandatory/1-fix-functions.js | 90 +++++++++++------- week-2/2-mandatory/2-function-creation.js | 43 +++++++-- week-2/2-mandatory/3-playing-computer.js | 13 ++- week-2/2-mandatory/4-sorting-algorithm.js | 13 ++- 23 files changed, 186 insertions(+), 68 deletions(-) create mode 100644 week-1/.DS_Store create mode 100644 week-1/1-exercises/.DS_Store create mode 100644 week-2/.DS_Store create mode 100644 week-2/1-exercises/.DS_Store diff --git a/.DS_Store b/.DS_Store index 4cb80315b900b193fd795b5d9b2fdab012e15a6d..e5f4e47ff1fa7e1197f1c9d0eb7c801d8d7ebfd3 100644 GIT binary patch delta 59 zcmZoMXfc@J&&a(oU^g=(_hcRx^U2jL*&Hdw$vH{+`8kuXvP5#iIEjJ2WkVlin$L+>mX@Iw#ovg7^0R1Hq*2W$bX>5lmFFgHJUpV?hyj7aAluXx7^Zy2~*X3pJUhet9#C;Z_& zoGvfd>t)$Rs*(ayKnh3!DIf(FDd4@Aw%#NvN&zV#1#SxX_o2}pd*PTEpALo?0f;N6 z!?=!Fg4jGk?1f_@Gc-#oF{xG~h9#Z(R&~8_OiVhgh7YSJTTLhyPv`wD%3(cGQ3^-s>NHnPs<^BK#e{hOIMVTJ}K|n~5poCCg$8R%!5OF#orJ_J%$(~)G zXID4H`3%73`-dxF24G5e#HWX``E&P?om9q%be^%sJ>Kz*4OhpRbI);uOFUvf;P04w z!yUHtSFCvMitF9Sa=U)nte^7E<1SH^6p#W^Knh3!DR5B0doOKzmZ&HNq<|DSDB$0R zMtAHA`^5NkFvJKzoG=~6b<7gP<_Tg~*e5bWv!oJ}YBge5(wT2n*A@1ONr%<&VRf_B zgko_!&u>u<>k<{EfD{-iaGKkh_y249FZ2J9q@5Iy0{=<@n=F=#IbW%I>*(dY*Eaes r{o7a@XKvtY6>{SlbH1u9bELee0)tGD($UUlo)DGAGj{ zb2-qN2>{u?)*E0AU`bUJHD*LV&$>=LctMmrMuP?wTGYh9A-eW+T;URr=(y^y^;aly zz)Rg%`-isO>vmSyFtEWJwc|#g(9`OtA=eB!F!z}(lsJ-&4)0?KX~G$9e3T=B0 zLV|%{AQ%V+f`OlBKrbW8a%C88Fc1s`1D_1&`H-lJh2vnDj}A7u1R&}&Ity*BB{U~F z7LJ1Cyf%wzE)d3KJUayXRrJx4CG)BH(o Z#ubi(p^l>8b2>2|0-2C#f`MOP-~+drDn|eS literal 0 HcmV?d00001 diff --git a/week-2/1-exercises/.DS_Store b/week-2/1-exercises/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..dca93e525430c4d20447460b35f2e62cdf14bab0 GIT binary patch literal 6148 zcmeHK%TB{E5FD2t$~!6&;+P-k0lpxVme-XZpbu143Qg4n32ymxX6>a)8VWa5q20(H zdp*0cCs7;&aQ(OGB@hAVun4yHS$$(NE~Q~D^&AkL&#}Y`FUWb#8*Fpzq5|^lj&Y41 zpW8dC&o9FQ`81!T<19;M>Rt3n8zbYDl0G7#$JQJLdn@+SdcZkuNSKiR%FH8D=6o|G zZ;$m-g9^4+^}r(xNC}gfGHAkJxkqg}Cm3q>1%yEdC7EX({-L)Ngd%u_sW1k6Y&=*tDG6WPW0%jRSXm;$@0 z0QYRM&S5~SO#xHD6j&=D--nn*Fi|W6`cDTde*_@5>GsC9oFybCR!kJjfE=N@5K0W8 zPLCKagwr1@FHtN5hHyANd^o+c(-VsGcW3_C)8UeUR+|E*KwW{o(2ZpOA8tSY*MqEQ z3YY@_N&(j%JPrC>lJ2dI#mQb9vplni39k&e4q?M@#pKFXe8J+4{#Y8sM6nD=56ylA MybM;E0)MK&CtNUXh5!Hn literal 0 HcmV?d00001 diff --git a/week-2/1-exercises/B-boolean-literals/exercise.js b/week-2/1-exercises/B-boolean-literals/exercise.js index 6c5060f..6e0c98c 100644 --- a/week-2/1-exercises/B-boolean-literals/exercise.js +++ b/week-2/1-exercises/B-boolean-literals/exercise.js @@ -6,6 +6,9 @@ */ var codeYourFutureIsGreat = true; +var mozafarIsCool = false; +var calculationCorrect = true; +var moreThan10Students = false; /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/1-exercises/C-comparison-operators/exercise.js b/week-2/1-exercises/C-comparison-operators/exercise.js index 58aee1c..82023b5 100644 --- a/week-2/1-exercises/C-comparison-operators/exercise.js +++ b/week-2/1-exercises/C-comparison-operators/exercise.js @@ -7,14 +7,14 @@ var studentCount = 16; var mentorCount = 9; -var moreStudentsThanMentors; // finish this statement +var moreStudentsThanMentors = true; // finish this statement var roomMaxCapacity = 25; -var enoughSpaceInRoom; // finish this statement +var enoughSpaceInRoom = false; // finish this statement var personA = "Daniel"; var personB = "Irina"; -var sameName; // finish this statement +var sameName = false; // finish this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/1-exercises/D-predicates/exercise.js b/week-2/1-exercises/D-predicates/exercise.js index f600521..f770da4 100644 --- a/week-2/1-exercises/D-predicates/exercise.js +++ b/week-2/1-exercises/D-predicates/exercise.js @@ -7,12 +7,12 @@ // Finish the predicate function to test if the passed number is negative (less than zero) function isNegative(number) { - + return number < 0; } // Finish the predicate function to test if the passed number is between 0 and 10 function isBetweenZeroAnd10(number) { - + return number > 0 && number < 10; } /* diff --git a/week-2/1-exercises/E-conditionals/exercise.js b/week-2/1-exercises/E-conditionals/exercise.js index acbaaa8..19fe991 100644 --- a/week-2/1-exercises/E-conditionals/exercise.js +++ b/week-2/1-exercises/E-conditionals/exercise.js @@ -8,7 +8,11 @@ var name = "Daniel"; var danielsRole = "mentor"; - +if (danielsRole === "mentor") { + console.log("Hi, I'm Daniel, I'm a mentor") +} else if (danielsRole === "student") { + console.log("Hi, I'm Daniel, I'm a student") +} /* EXPECTED RESULT --------------- diff --git a/week-2/1-exercises/F-logical-operators/exercise.js b/week-2/1-exercises/F-logical-operators/exercise.js index a8f2945..b7c7e87 100644 --- a/week-2/1-exercises/F-logical-operators/exercise.js +++ b/week-2/1-exercises/F-logical-operators/exercise.js @@ -11,16 +11,33 @@ var cssLevel = 4; // Finish the statement to check whether HTML, CSS knowledge are above 5 // (hint: use the comparison operator from before) -var htmlLevelAbove5; -var cssLevelAbove5; + + if (htmlLevel > 5) { + var htmlLevelAbove5 = true; + } else {false + } + if (cssLevel > 5) { + var cssLevelAbove5 = true; + } else {var cssLevelAbove5 = false;} + // Finish the next two statement // Use the previous variables and logical operators // Do not "hardcode" the answers var cssAndHtmlAbove5; var cssOrHtmlAbove5; +if (htmlLevel > 5 && cssLevel > 5) { + cssAndHtmlAbove5 = true; +} else {cssAndHtmlAbove5 = false} + +if (htmlLevel > 5 || cssLevel > 5) { + cssOrHtmlAbove5 = true; +} else { + cssOrHtmlAbove5 = false; +} /* + DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/week-2/1-exercises/F-logical-operators/exercise2.js b/week-2/1-exercises/F-logical-operators/exercise2.js index 6f4199c..31c0b9d 100644 --- a/week-2/1-exercises/F-logical-operators/exercise2.js +++ b/week-2/1-exercises/F-logical-operators/exercise2.js @@ -5,8 +5,23 @@ Update the code so that you get the expected result. */ -function isNegative() {} +function isNegative(number) { + return number < 0; +} + +function isBetween5and10 (number) { + return number >= 5 && number <= 10; +} +function isShortName (name) { + let stringLength = name.length; + return stringLength < 8; + +} + +function startsWithD (name) { + return name[0] === "D"; +} /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/week-2/1-exercises/G-conditionals-2/exercise-1.js b/week-2/1-exercises/G-conditionals-2/exercise-1.js index 54708ef..d560c3f 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-1.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-1.js @@ -7,7 +7,9 @@ */ function negativeOrPositive(number) { - + if (number < 0) { + return "negative"; + } else {return "positive"} } /* diff --git a/week-2/1-exercises/G-conditionals-2/exercise-2.js b/week-2/1-exercises/G-conditionals-2/exercise-2.js index 313f3fb..5b7aaf2 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-2.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-2.js @@ -8,7 +8,9 @@ */ function studentPassed(grade) { - + if (grade < 50) { + return "failed"; + } else {return "passed"} } /* diff --git a/week-2/1-exercises/G-conditionals-2/exercise-3.js b/week-2/1-exercises/G-conditionals-2/exercise-3.js index a79cf30..bcff088 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-3.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-3.js @@ -9,8 +9,15 @@ */ function calculateGrade(mark) { - -} + if (mark >= 80) { + return "A"; + } else if (mark < 80 && mark > 60) { + return "B" + } else if (mark < 60 && mark >= 50){ + return "C" + } + else {return "F"} +} /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/1-exercises/G-conditionals-2/exercise-4.js b/week-2/1-exercises/G-conditionals-2/exercise-4.js index bd5bb1e..4418a29 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-4.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-4.js @@ -9,6 +9,9 @@ */ function containsCode(sentence) { + if (sentence.includes("code") === true) { + return true + } else {return false} } diff --git a/week-2/1-exercises/H-array-literals/exercise.js b/week-2/1-exercises/H-array-literals/exercise.js index d6dc556..9826af8 100644 --- a/week-2/1-exercises/H-array-literals/exercise.js +++ b/week-2/1-exercises/H-array-literals/exercise.js @@ -4,8 +4,8 @@ Declare some variables assigned to arrays of values */ -var numbers = []; // add numbers from 1 to 10 into this array -var mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares +var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // add numbers from 1 to 10 into this array +var mentors = ["Daniel", "Irina", "Rares"]; // Create an array with the names of the mentors: Daniel, Irina and Rares /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/1-exercises/I-array-properties/exercise.js b/week-2/1-exercises/I-array-properties/exercise.js index f9aec89..eb8e56b 100644 --- a/week-2/1-exercises/I-array-properties/exercise.js +++ b/week-2/1-exercises/I-array-properties/exercise.js @@ -6,9 +6,10 @@ */ function isEmpty(arr) { - return; // complete this statement + if (arr.length > 0) + {return false;} // complete this statement + else {return true} } - /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/week-2/1-exercises/J-array-get-set/exercise.js b/week-2/1-exercises/J-array-get-set/exercise.js index 3b95694..18d072c 100644 --- a/week-2/1-exercises/J-array-get-set/exercise.js +++ b/week-2/1-exercises/J-array-get-set/exercise.js @@ -5,11 +5,11 @@ */ function first(arr) { - return; // complete this statement + return arr[0]; // complete this statement } function last(arr) { - return; // complete this statement + return arr[arr.length - 1]; // complete this statement } /* diff --git a/week-2/1-exercises/J-array-get-set/exercises2.js b/week-2/1-exercises/J-array-get-set/exercises2.js index 97f126f..005d4ba 100644 --- a/week-2/1-exercises/J-array-get-set/exercises2.js +++ b/week-2/1-exercises/J-array-get-set/exercises2.js @@ -7,7 +7,8 @@ */ var numbers = [1, 2, 3]; // Don't change this array literal declaration - +numbers.push(4); +numbers[0] = 1; /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/week-2/2-mandatory/1-fix-functions.js b/week-2/2-mandatory/1-fix-functions.js index 6316fad..731db17 100644 --- a/week-2/2-mandatory/1-fix-functions.js +++ b/week-2/2-mandatory/1-fix-functions.js @@ -1,90 +1,110 @@ // The below functions are syntactically correct but not outputting the right results. // Look at the tests and see how you can fix them. -function mood() { - let isHappy = true; - - if (isHappy) { +function mood(isHappy) { + if (isHappy === true) { return "I am happy"; } else { return "I am not happy"; } } -function greaterThan10() { - let num = 10; - let isBigEnough; - - if (isBigEnough) { - return "num is greater than or equal to 10"; +function greaterThan10(num) { + let isBigEnough = 10; + if (num > isBigEnough) { + return "num is greater than 10"; } else { return "num is not big enough"; } } -function sortArray() { - let letters = ["a", "n", "c", "e", "z", "f"]; - let sortedLetters; +function sortArray(letters) { + + let sortedLetters = letters.sort(); return sortedLetters; } function first5() { let numbers = [1, 2, 3, 4, 5, 6, 7, 8]; - let sliced; - + numbers.length = 5; + let sliced = numbers; return sliced; } function get3rdIndex(arr) { - let index = 3; - let element; + let index = arr[3]; + let element = index; return element; } /* ======= TESTS - DO NOT MODIFY ===== */ -function test(test_name, expr) { +const util = require("util"); +function test(test_name, actual, expected) { let status; - if (expr) { + let isEqual; + if (Array.isArray(expected)) { + isEqual = arraysEqual(actual, expected); + } else { + isEqual = actual === expected; + } + if (isEqual) { status = "PASSED"; } else { - status = "FAILED"; + status = `FAILED: expected: ${util.inspect( + expected + )} but your function returned: ${util.inspect(actual)}`; } - console.log(`${test_name}: ${status}`); } - function arraysEqual(a, b) { if (a === b) return true; if (a == null || b == null) return false; if (a.length != b.length) return false; - for (let i = 0; i < a.length; ++i) { if (a[i] !== b[i]) return false; } - return true; } - -test("mood function works", mood() === "I am not happy"); +test("mood function works for true", mood(true), "I am happy"); +test("mood function works for false", mood(false), "I am not happy"); test( - "greaterThanTen function works", - greaterThan10() === "num is greater than or equal to 10" + "greaterThanTen function works for 11", + greaterThan10(11), + "num is greater than 10" ); test( - "sortArray function works", - arraysEqual(sortArray(), ["a", "c", "e", "f", "n", "z"]) + "greaterThanTen function works for 10", + greaterThan10(10), + "num is not big enough" ); -test("first5 function works", arraysEqual(first5(), [1, 2, 3, 4, 5])); - +test( + "greaterThanTen function works for 9", + greaterThan10(9), + "num is not big enough" +); +test("sortArray function works", sortArray(["a", "n", "c", "e", "z", "f"]), [ + "a", + "c", + "e", + "f", + "n", + "z", +]); +let numbers = [1, 2, 3, 4, 5, 6, 7, 8]; +test("first5 function works", first5(numbers), [1, 2, 3, 4, 5]); +if (!arraysEqual(numbers, [1, 2, 3, 4, 5, 6, 7, 8])) { + console.log("PROBLEM: first5 changed its input array - it shouldn't!"); +} test( "get3rdIndex function works - case 1", - get3rdIndex(["fruit", "banana", "apple", "strawberry", "raspberry"]) === - "strawberry" + get3rdIndex(["fruit", "banana", "apple", "strawberry", "raspberry"]), + "strawberry" ); test( "get3rdIndex function works - case 2", - get3rdIndex([11, 37, 62, 18, 19, 3, 30]) === 18 + get3rdIndex([11, 37, 62, 18, 19, 3, 30]), + 18 ); diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index bf7ecfd..bb436ca 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -5,9 +5,18 @@ Write a function that: - removes any forward slashes (/) in the strings - makes the string all lowercase */ -function tidyUpString(strArr) {} +function tidyUpString(strArr) { + for (let i = 0; i < strArr.length; i++) { + let removed = strArr[i].trim(); + let remBackSlash = removed.replace(/\//g, ""); + let smallStrr = remBackSlash.toLowerCase(); + strArr[i] = smallStrr; + } + return strArr; +} /* + Complete the function to check if the variable `num` satisfies the following requirements: - is a number - is even @@ -15,7 +24,13 @@ Complete the function to check if the variable `num` satisfies the following req Tip: use logical operators */ -function validate(num) {} +function validate(num) { + if (typeof num === "number" && num % 2 === 0 && num <= 100) { + return true; + } else { + return false; + } +} /* Write a function that removes an element from an array @@ -26,7 +41,9 @@ The function must: */ function remove(arr, index) { - return; // complete this statement + let removed = arr.splice(index, 1); + + return arr; // complete this statement } /* @@ -37,10 +54,18 @@ Write a function that: - numbers greater 100 must be replaced with 100 */ + function formatPercentage(arr) { - + for (let i = 0; i < arr.length; i++) { + if (arr[i] > 100) { + arr[i] = 100; + } + let dec = arr[i].toFixed(2); + dec = parseFloat(dec); + arr[i] = dec.toString() + "%"; + } + return arr; } - /* ======= TESTS - DO NOT MODIFY ===== */ function arraysEqual(a, b) { @@ -72,7 +97,7 @@ test( "daniel", "irina", "gordon", - "ashleigh" + "ashleigh", ]) ); test( @@ -101,7 +126,7 @@ test( "c", "d", "e", - "f" + "f", ]) ); @@ -111,6 +136,6 @@ test( "23%", "18%", "100%", - "0.37%" + "0.37%", ]) -); \ No newline at end of file +); diff --git a/week-2/2-mandatory/3-playing-computer.js b/week-2/2-mandatory/3-playing-computer.js index 0fa7c04..e9a9958 100644 --- a/week-2/2-mandatory/3-playing-computer.js +++ b/week-2/2-mandatory/3-playing-computer.js @@ -18,17 +18,16 @@ let x = 2; let a = 6; -const f1 = function(a, b) { +const f1 = function (a, b) { return a + b; }; -const f2 = function(a, b) { +const f2 = function (a, b) { return a + b + x; }; console.log(x); console.log(a); -console.log(b); for (let i = 0; i < 5; ++i) { a = a + 1; @@ -40,3 +39,11 @@ for (let i = 0; i < 5; ++i) { console.log(e); } } +/* +1. The console.log(b) threw the error. +3. 2,6,4,9,6,13,8 +4. 2 times +5. 3 times +6. 1 +7. I think 7 if you mean the 'a' variable in the for loop. +*/ diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index 3603942..6abb7bb 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -14,7 +14,18 @@ You don't have to worry about making this algorithm work fast! The idea is to ge "think" like a computer and practice your knowledge of basic JavaScript. */ -function sortAges(arr) {} +function sortAges(arr) { + let arr2 = []; + var length = arr2.length; + for (i = 0; i < arr.length; i++) + if (typeof arr[i] === "number") { + arr2.push(arr[i]); + } else { + } + arr2.sort(); + + console.log(arr2); +} /* ======= TESTS - DO NOT MODIFY ===== */ From ba20acb70ef3b2debf2b0a5605a2ca8c55991b59 Mon Sep 17 00:00:00 2001 From: MartinBoylan <63868146+MartinBoylan@users.noreply.github.com> Date: Mon, 6 Jul 2020 23:29:05 +0100 Subject: [PATCH 3/3] changes to week 3 homework --- .DS_Store | Bin 6148 -> 6148 bytes week-3/.DS_Store | Bin 6148 -> 6148 bytes week-3/1-exercises/.DS_Store | Bin 0 -> 6148 bytes week-3/1-exercises/A-array-find/exercise.js | 7 +- week-3/1-exercises/C-array-every/exercise.js | 6 +- .../1-exercises/G-array-methods/exercise.js | 2 +- .../1-exercises/G-array-methods/exercise2.js | 2 +- week-3/2-mandatory/1-oxygen-levels.js | 14 +++- week-3/2-mandatory/2-bush-berries.js | 27 ++++++-- week-3/2-mandatory/3-space-colonies.js | 23 +++++-- week-3/2-mandatory/4-eligible-students.js | 63 ++++++++++-------- week-3/2-mandatory/5-journey-planner.js | 20 ++++-- week-3/2-mandatory/6-lane-names.js | 7 +- week-3/2-mandatory/7-password-validator.js | 28 +++++++- 14 files changed, 147 insertions(+), 52 deletions(-) create mode 100644 week-3/1-exercises/.DS_Store diff --git a/.DS_Store b/.DS_Store index e5f4e47ff1fa7e1197f1c9d0eb7c801d8d7ebfd3..ebd497c809fd57d69af08180b61028c3d93a0367 100644 GIT binary patch delta 59 zcmZoMXfc@J&&aniU^g=(-)0^b8Ai^ul;Y&1{QMk-%@VA(jFb6UCAf@XVvL(z*~%F= Jvvd6A2LSfM5cL26 delta 37 tcmZoMXfc@J&&a(oU^g=(_hudz8OF_yth$Vw7qF!>PHgbr%+B$b9{|oh3lRVS diff --git a/week-3/.DS_Store b/week-3/.DS_Store index 7db7cc1e281647226e44b608a65874f8c62b6f04..d8aac89f40be638c5a25aef0661bf1b6ed6eea32 100644 GIT binary patch delta 488 zcmZoMXfc=|#>B)qu~2NHo}wr#0|Nsi1A_nqLn;s^GvqU*Fr;oQT+UbzlHp@8V9;eq zV<81nwap+ zyp;TMr~J~qlwzv~+?PD?3HP69d{WCGssDGM&j%gN76 z2dV?9l~;$^0UY96&oj7O`xO5Lv?v02%#q>i_@% literal 6148 zcmeHKy-ve07(AB_6)n&W#*8dTbY@9QieT;w(ElRRrYe8xmZcjrkATEWAn{BLjBuZA z1aUyHfGF}8eLlyzi{p!8#{g90qE`c|07^{3;wp;|Las~ZqF`GpM5XUBLmPAKV1Sbx z+c$UzyaRvD0r_?-sPmg`W5(m{`<Zl$a)dmh6)qrE1@m_6o zG0Lh7ZAV?gp>YIPT6LP`BP9R&oufH^Jgl|4$#_cMYvefNB#P`?D&5{JcJH4a>Lh=_ z>wSwi9ev&BWotHxlgW_%aOU^1ln&T8S1K>%)BA_^4tNKC(gB$t0;XVSF*T^C4ixwMJTTC6i7D$B{T1*YHh2eh$v<<%S4*aSEFOA!qIRF3v diff --git a/week-3/1-exercises/.DS_Store b/week-3/1-exercises/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b9aa7e96f8787616846272a9afa72c4d1f4f84fd GIT binary patch literal 6148 zcmeHK%Sr=55Ukc50(!{NFwHK>ae{Hz?S>r23P=?(;e~QVQT)|ePU;oF(RGsc*O?qxW*Pwlj_q6=U(ELoDJFE z`7ao@!`tJ-Zufkes;m@{0#ZNOzY$yO7J#p!&1i*i^` zRFncz;8=n4+%CNTujxO`|HmZlq<|FoR|?o{b+=mbO4VB@m-AlR==XH5`J}sX9TbLW l$HZvI+;}^_ilVG*zUK2@I3@<2`JfZ^GvK<&q`+S*Z~*P=6^Q@< literal 0 HcmV?d00001 diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index d7fd51f..f01c50d 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -5,9 +5,14 @@ // write your code here + + var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; -var longNameThatStartsWithA = findLongNameThatStartsWithA(names); +function LongNamesStartWithA(arr) { + return arr[0] === "A" && arr.length > 7 +} +var longNameThatStartsWithA = names.find(LongNamesStartWithA); console.log(longNameThatStartsWithA); diff --git a/week-3/1-exercises/C-array-every/exercise.js b/week-3/1-exercises/C-array-every/exercise.js index b515e94..41e1439 100644 --- a/week-3/1-exercises/C-array-every/exercise.js +++ b/week-3/1-exercises/C-array-every/exercise.js @@ -4,8 +4,10 @@ var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; var group = ["Austine", "Dany", "Swathi", "Daniel"]; - -var groupIsOnlyStudents; // complete this statement +function onlyStudents (names) { + return names === students +} +var groupIsOnlyStudents = group.every(onlyStudents)// complete this statement if (groupIsOnlyStudents) { console.log("The group contains only students"); diff --git a/week-3/1-exercises/G-array-methods/exercise.js b/week-3/1-exercises/G-array-methods/exercise.js index 44e9c80..6a8e4b3 100644 --- a/week-3/1-exercises/G-array-methods/exercise.js +++ b/week-3/1-exercises/G-array-methods/exercise.js @@ -4,7 +4,7 @@ */ var numbers = [3, 2, 1]; -var sortedNumbers; // complete this statement +var sortedNumbers = numbers.sort(); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/G-array-methods/exercise2.js b/week-3/1-exercises/G-array-methods/exercise2.js index 3dd24a1..b9d95c9 100644 --- a/week-3/1-exercises/G-array-methods/exercise2.js +++ b/week-3/1-exercises/G-array-methods/exercise2.js @@ -7,7 +7,7 @@ var mentors = ["Daniel", "Irina", "Rares"]; var students = ["Rukmini", "Abdul", "Austine", "Swathi"]; -var everyone; // complete this statement +var everyone = students.concat(mentors); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 3c02135..c73b92d 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,10 +9,19 @@ To be safe, they need to land on the first unamed planet that has Oxygen levels Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5% */ -function safeLevels() { +function niceFunction(oxygenLevel) { + + return oxygenLevel > "19.5%" && oxygenLevel < "23.5%" +} + + +function safeLevels(arrOxygen) { + return arrOxygen.find(niceFunction) } + + /* ======= TESTS - DO NOT MODIFY ===== */ const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"] @@ -37,4 +46,5 @@ test( test( "safeLevels function works - case 2", safeLevels(oxygenLevels2) === "20.2%" -); \ No newline at end of file +); + diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index d900323..ee9c743 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,14 +10,23 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function hasAllPinkBerries(colour) { + return colour === "pink"; } +function bushChecker(arrColour) { + let bushes = arrColour.every(hasAllPinkBerries); + + if (bushes) { + return "Bush is safe to eat from"; + } else { + return "Toxic! Leave bush alone!"; + } +} /* ======= TESTS - DO NOT MODIFY ===== */ -let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"] -let bushBerryColours2 = ["pink", "pink", "pink", "pink"] +let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"]; +let bushBerryColours2 = ["pink", "pink", "pink", "pink"]; function test(test_name, expr) { let status; @@ -30,5 +39,11 @@ function test(test_name, expr) { console.log(`${test_name}: ${status}`); } -test("bushChecker funtion works - case 1", bushChecker(bushBerryColours1) === "Toxic! Leave bush alone!") -test("bushChecker funtion works - case 1", bushChecker(bushBerryColours2) === "Bush is safe to eat from") +test( + "bushChecker funtion works - case 1", + bushChecker(bushBerryColours1) === "Toxic! Leave bush alone!" +); +test( + "bushChecker funtion works - case 1", + bushChecker(bushBerryColours2) === "Bush is safe to eat from" +); diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index f99891a..3e2601a 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,10 +8,18 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { +function doesItstartWithA(name) { + return name[0] === "A" && name.length > 9; +} +function colonisers(voyagerArr) { + return voyagerArr.filter(doesItstartWithA) } + + + + /* ======= TESTS - DO NOT MODIFY ===== */ const voyagers = [ @@ -26,7 +34,7 @@ const voyagers = [ "Asimov", "Oscar family", "Avery family", - "Archer family" + "Archer family", ]; function arraysEqual(a, b) { @@ -52,6 +60,11 @@ function test(test_name, expr) { console.log(`${test_name}: ${status}`); } -test("colonisers function works", - arraysEqual(colonisers(voyagers), ["Adam family", "Avery family", "Archer family"]) -) \ No newline at end of file +test( + "colonisers function works", + arraysEqual(colonisers(voyagers), [ + "Adam family", + "Avery family", + "Archer family", + ]) +); diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 6424b01..5a83137 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,11 +7,18 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { +function giveMeNames(attendanceArr) { + return attendanceArr[0]; +} +function giveMeNumbers(attendanceArr) { + return attendanceArr[1] >= 8; +} +function eligibleStudents(attendancesArr) { + return attendancesArr.filter(giveMeNumbers).map(giveMeNames); } -/* ======= TESTS - DO NOT MODIFY ===== */ +/*======= TESTS - DO NOT MODIFY ===== */ const attendances = [ ["Ahmed", 8], @@ -19,34 +26,38 @@ const attendances = [ ["Elamin", 6], ["Adam", 7], ["Tayoa", 11], - ["Nina", 10] -] + ["Nina", 10], +]; function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; - - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - - return true; + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; + + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + + return true; } function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = "PASSED"; + } else { + status = "FAILED"; + } + + console.log(`${test_name}: ${status}`); } -test("eligibleStudents function works", - arraysEqual( - eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"] - ) -) \ No newline at end of file +test( + "eligibleStudents function works", + arraysEqual(eligibleStudents(attendances), [ + "Ahmed", + "Clement", + "Tayoa", + "Nina", + ]) +); diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 53499c3..13f5f34 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,11 +7,21 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { - +function journeyPlanner(arr, transport) { + let result = []; + let res = arr.map(b => b.find(x => x === transport)); //output [tube, tube, tube, undefined] + if(res[0] === "tube" || res[1] === 'tube' || res[2] === 'tube' || res[3] === 'tube') { + result.push("Angel", "London Bridge", "Tower Bridge"); + }else if(res[0] === 'bus' || res[1] === 'bus' || res[2] === 'bus' || res[3] === 'bus'){ + result.push("Angel", "Tower Bridge", "Greenwich"); + }else if(res[0] === 'river boat' || res[1] === 'river boat' || res[2] === 'river boat' || res[3] === 'river boat'){ + result.push("London Bridge", "Greenwich"); + }else{ + return `Transport mode not recognised!`; + } + return result; } - -/* ======= TESTS - DO NOT MODIFY ===== */ + /*======= TESTS - DO NOT MODIFY ===== */ const londonLocations = [ ["Angel", "tube", "bus"], @@ -63,3 +73,5 @@ test("journeyPlanner function works - case 3", ["Angel", "London Bridge", "Tower Bridge"] ) ) + + \ No newline at end of file diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index eddfe44..c1d794e 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,10 +4,15 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { +function IncludeIt(names) { + return names.includes("Lane") +} +function getLanes(names) { + return names.filter(IncludeIt) } + /* ======= TESTS - DO NOT MODIFY ===== */ const streetNames = [ diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 57b3d53..ab616b8 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -22,12 +22,33 @@ PasswordValidationResult= [false, false, false, false, true] */ -function validatePasswords(passwords) { +const passwords1 = ["Se%5", "TktE.TJTU", "384#HsHF", "dvyyeyy!5", "tryT3729"]; +const passwords2 = ["StUFf27%", "Pl3nty!", "Jai33", "shajsaUA**&&", "Pl3nty!"]; +function checkPasswords(passwords) { + return ( + passwords.length >= 5 && + passwords.split("").some(function (a) { + return a >= "A" && a <= "Z"; + }) && + passwords.split("").some(function (b) { + return b >= "a" && b <= "z"; + }) && + passwords.split("").some(function (c) { + return c >= "0" && c <= "9"; + }) && + passwords.split("").some(function (d) { + return ["!", "#", "$", "%", "."].indexOf(d) >= 0; + }) + ); +} +function otherFunction(passwordArr) { + return passwordArr.map(checkPasswords); } +console.log(otherFunction(passwords2)); /* ======= TESTS - DO NOT MODIFY ===== */ - +/* const passwords1 = ["Se%5", "TktE.TJTU", "384#HsHF", "dvyyeyy!5", "tryT3729"] const passwords2 = ["StUFf27%", "Pl3nty!", "Jai33", "shajsaUA**&&", "Pl3nty!"] @@ -66,4 +87,5 @@ test( arraysEqual( validatePasswords(passwords2), [true, true, false, false, false] ) - ); + ); + */