From 05bed680d9b37ca414a6f5cfb12cd43e2e875c64 Mon Sep 17 00:00:00 2001 From: edksam Date: Fri, 19 Jun 2020 14:52:21 +0100 Subject: [PATCH 01/11] halve.js try out --- week-1/1-exercises/J-functions/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-1/1-exercises/J-functions/exercise.js b/week-1/1-exercises/J-functions/exercise.js index 0ae5850..0fc4c36 100644 --- a/week-1/1-exercises/J-functions/exercise.js +++ b/week-1/1-exercises/J-functions/exercise.js @@ -1,5 +1,6 @@ function halve(number) { // complete the function here + return number / 2; } var result = halve(12); From 800871a7771ebc8be81a8a7e85425fe1f9562891 Mon Sep 17 00:00:00 2001 From: edksam Date: Sat, 20 Jun 2020 23:02:14 +0100 Subject: [PATCH 02/11] Initial Commit --- week-2/1-exercises/B-boolean-literals/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-2/1-exercises/B-boolean-literals/exercise.js b/week-2/1-exercises/B-boolean-literals/exercise.js index 6c5060f..4a69f14 100644 --- a/week-2/1-exercises/B-boolean-literals/exercise.js +++ b/week-2/1-exercises/B-boolean-literals/exercise.js @@ -5,7 +5,7 @@ Add the required variables with the correct boolean values assigned. */ -var codeYourFutureIsGreat = true; +const codeYourFutureIsGreat = false; /* DO NOT EDIT BELOW THIS LINE From 80e5eb9a9b68a598d7a5fb8c40f1718fb6f51086 Mon Sep 17 00:00:00 2001 From: edksam Date: Fri, 26 Jun 2020 17:16:02 +0100 Subject: [PATCH 03/11] Fix functions and functions creationsorted --- week-2/2-mandatory/1-fix-functions.js | 27 ++++++++--------- week-2/2-mandatory/2-function-creation.js | 36 ++++++++++++++++------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/week-2/2-mandatory/1-fix-functions.js b/week-2/2-mandatory/1-fix-functions.js index 6316fad..f02f1ef 100644 --- a/week-2/2-mandatory/1-fix-functions.js +++ b/week-2/2-mandatory/1-fix-functions.js @@ -1,21 +1,18 @@ // 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; - +function mood(isHappy) { + // let isHappy = true; if (isHappy) { return "I am happy"; - } else { - return "I am not happy"; } + return "I am not happy"; } -function greaterThan10() { +function greaterThan10(isBigEnough) { let num = 10; - let isBigEnough; - - if (isBigEnough) { + // let isBigEnough; + if (num >= 10) { return "num is greater than or equal to 10"; } else { return "num is not big enough"; @@ -23,23 +20,23 @@ function greaterThan10() { } function sortArray() { - let letters = ["a", "n", "c", "e", "z", "f"]; + const letters = ["a", "n", "c", "e", "z", "f"]; let sortedLetters; - + sortedLetters = letters.sort(); return sortedLetters; } function first5() { - let numbers = [1, 2, 3, 4, 5, 6, 7, 8]; + const numbers = [1, 2, 3, 4, 5, 6, 7, 8]; let sliced; - + sliced = numbers.slice(0, 5); return sliced; } function get3rdIndex(arr) { - let index = 3; + const index = 3; let element; - + element = arr[index]; return element; } diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index bf7ecfd..79c0f77 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -5,7 +5,15 @@ Write a function that: - removes any forward slashes (/) in the strings - makes the string all lowercase */ -function tidyUpString(strArr) {} + function tidyUpString(strArr) { +// // let names = strArr[i]; +// // for (let i=0; i < names.length; i++) { +// // console.log(names) +// // } +// for (let names of strArr) { +// console.log(names) +// } + } /* Complete the function to check if the variable `num` satisfies the following requirements: @@ -15,7 +23,16 @@ 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 +43,8 @@ The function must: */ function remove(arr, index) { - return; // complete this statement + const removed = arr.splice(index, 1); + return arr; } /* @@ -37,9 +55,7 @@ Write a function that: - numbers greater 100 must be replaced with 100 */ -function formatPercentage(arr) { - -} +function formatPercentage(arr) {} /* ======= TESTS - DO NOT MODIFY ===== */ @@ -72,7 +88,7 @@ test( "daniel", "irina", "gordon", - "ashleigh" + "ashleigh", ]) ); test( @@ -101,7 +117,7 @@ test( "c", "d", "e", - "f" + "f", ]) ); @@ -111,6 +127,6 @@ test( "23%", "18%", "100%", - "0.37%" + "0.37%", ]) -); \ No newline at end of file +); From 9402f5a91f1871146a71d8b65263988a4238ae02 Mon Sep 17 00:00:00 2001 From: edksam Date: Sat, 27 Jun 2020 01:13:48 +0100 Subject: [PATCH 04/11] playing computer done --- week-2/2-mandatory/2-function-creation.js | 15 ++++++++++++++- week-2/2-mandatory/3-playing-computer.js | 17 +++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index 79c0f77..eb24a5a 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -55,7 +55,20 @@ Write a function that: - numbers greater 100 must be replaced with 100 */ -function formatPercentage(arr) {} +function formatPercentage(arr) { + const percentage = arr.map(function(n) { + if (n < 100) + { + console.log(`${Number(n.toFixed(2))}%`); + } + else + { + console.log("100%"); + } + + }) + +} /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-2/2-mandatory/3-playing-computer.js b/week-2/2-mandatory/3-playing-computer.js index 0fa7c04..fad33ee 100644 --- a/week-2/2-mandatory/3-playing-computer.js +++ b/week-2/2-mandatory/3-playing-computer.js @@ -6,13 +6,14 @@ Answer the following questions: - 1. This program throws an error. Why? (If you can't find it, try executing it). - 2. Remove the line that throws the error. - 3. What is printed to the console? - 4. How many times is "f1" called? - 5. How many times is "f2" called? - 6. What value does the "a" parameter take in the first "f1" call? - 7. What is the value of the "a" outer variable when "f1" is called for the first time? + 1. This program throws an error. Why? (If you can't find it, try executing it). Ans: ReferenceError: b is not defined. + Trying to console out b which is not a defined variable outside the function block. + 2. Remove the line that throws the error. Ans: console.log(b) is removed. + 3. What is printed to the console? Ans: console prints out 2 6 4 9 6 13 8 + 4. How many times is "f1" called? Ans: f1 is the else which is 9 and 13 ( twice) + 5. How many times is "f2" called? Ans: f2 even numbers are 2 , 6, 4, 6, 8 (5 times) + 6. What value does the "a" parameter take in the first "f1" call? Ans: 1st parameter call a = 6 + 7. What is the value of the "a" outer variable when "f1" is called for the first time? Ans: a + 1 = 7 */ let x = 2; @@ -28,7 +29,7 @@ const f2 = function(a, b) { console.log(x); console.log(a); -console.log(b); +// console.log(b); for (let i = 0; i < 5; ++i) { a = a + 1; From 3bb13898660db7a334e29889e64f6211b0683f3f Mon Sep 17 00:00:00 2001 From: edksam Date: Sun, 28 Jun 2020 00:54:48 +0100 Subject: [PATCH 05/11] sorting-algorithn attempted --- week-2/1-exercises/B-boolean-literals/exercise.js | 3 +++ week-2/1-exercises/D-predicates/exercise.js | 15 +++++---------- week-2/2-mandatory/2-function-creation.js | 8 +------- week-2/2-mandatory/4-sorting-algorithm.js | 10 +++++++++- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/week-2/1-exercises/B-boolean-literals/exercise.js b/week-2/1-exercises/B-boolean-literals/exercise.js index 4a69f14..9317628 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 @@ */ const codeYourFutureIsGreat = false; +const mozafarIsCool = false; +const calculationCorrect = true; +const moreThan10Students = false; /* 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..39bdd0c 100644 --- a/week-2/1-exercises/D-predicates/exercise.js +++ b/week-2/1-exercises/D-predicates/exercise.js @@ -6,21 +6,17 @@ */ // Finish the predicate function to test if the passed number is negative (less than zero) -function isNegative(number) { - -} +function isNegative(number) {} // Finish the predicate function to test if the passed number is between 0 and 10 -function isBetweenZeroAnd10(number) { - -} +function isBetweenZeroAnd10(number) {} /* DO NOT EDIT BELOW THIS LINE --------------------------- */ -var number = 5; -var numberNegative = isNegative(number); -var numberBetweenZeroAnd10 = isBetweenZeroAnd10(number); +const number = 5; +const numberNegative = isNegative(number); +const numberBetweenZeroAnd10 = isBetweenZeroAnd10(number); console.log("The number in test is " + number); console.log("Is the number negative? " + numberNegative); console.log("Is the number between 0 and 10? " + numberBetweenZeroAnd10); @@ -32,4 +28,3 @@ console.log("Is the number between 0 and 10? " + numberBetweenZeroAnd10); Is the number negative? false Is the number between 0 and 10? true */ - diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index eb24a5a..0c44911 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -6,13 +6,7 @@ Write a function that: - makes the string all lowercase */ function tidyUpString(strArr) { -// // let names = strArr[i]; -// // for (let i=0; i < names.length; i++) { -// // console.log(names) -// // } -// for (let names of strArr) { -// console.log(names) -// } + } /* diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index 3603942..24fef43 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -14,7 +14,15 @@ 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) { +const sorted = arr.filter(function(value) { + return typeof value === "number" +}); + const ascendSort = sorted.sort(function(a, b) { + return a - b; + }) + console.log(ascendSort); + } /* ======= TESTS - DO NOT MODIFY ===== */ From 41a85bebbaf1bfd615bbccba5959937578d35a88 Mon Sep 17 00:00:00 2001 From: edksam Date: Sun, 28 Jun 2020 21:52:15 +0100 Subject: [PATCH 06/11] return statement added to make it pass --- week-2/2-mandatory/4-sorting-algorithm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index 24fef43..3778824 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -21,7 +21,7 @@ const sorted = arr.filter(function(value) { const ascendSort = sorted.sort(function(a, b) { return a - b; }) - console.log(ascendSort); +return ascendSort; } /* ======= TESTS - DO NOT MODIFY ===== */ From bd7196742ade3e0eece33b2064ef9bbea8c8a270 Mon Sep 17 00:00:00 2001 From: edksam Date: Sun, 28 Jun 2020 23:13:51 +0100 Subject: [PATCH 07/11] unintended changes hanging --- week-1/3-extra/2-piping.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/week-1/3-extra/2-piping.js b/week-1/3-extra/2-piping.js index 93c0bf7..015e21c 100644 --- a/week-1/3-extra/2-piping.js +++ b/week-1/3-extra/2-piping.js @@ -16,15 +16,15 @@ the final result to the variable goodCode */ -function add() { - +function add(num1, num2) { + return num1 + num2; } -function multiply() { - +function multiply(num1, num3) { + return num1 * num2; } -function format() { +function format(num) { } From 82d66b2c50be6767193d8ae460a47b22405b0ed2 Mon Sep 17 00:00:00 2001 From: edksam Date: Fri, 3 Jul 2020 12:19:15 +0100 Subject: [PATCH 08/11] changes so far-mandatory --- week-3/1-exercises/A-array-find/exercise.js | 4 +++ week-3/1-exercises/B-array-some/exercise.js | 11 ++++-- week-3/2-mandatory/1-oxygen-levels.js | 10 ++++-- week-3/2-mandatory/2-bush-berries.js | 4 +-- week-3/2-mandatory/3-space-colonies.js | 38 +++++++++++++++++++-- week-3/2-mandatory/7-password-validator.js | 10 +++++- 6 files changed, 68 insertions(+), 9 deletions(-) diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index d7fd51f..65df5fb 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -7,6 +7,10 @@ var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; +var findName = names.find(name => { + return name.charAt(0) || name.length > 7; +}) + var longNameThatStartsWithA = findLongNameThatStartsWithA(names); console.log(longNameThatStartsWithA); diff --git a/week-3/1-exercises/B-array-some/exercise.js b/week-3/1-exercises/B-array-some/exercise.js index 965c052..4610f29 100644 --- a/week-3/1-exercises/B-array-some/exercise.js +++ b/week-3/1-exercises/B-array-some/exercise.js @@ -6,7 +6,7 @@ - Do not edit any of the existing code */ -var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; +var pairsByIndex = [[0, 3], [1, 2], [2, 1],null,[3, 0]]; // If there is a null value in the array exit the program with the error code // https://nodejs.org/api/process.html#process_process_exit_code @@ -18,7 +18,14 @@ var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; var pairs = pairsByIndex.map(function(indexes) { var student = students[indexes[0]]; var mentor = mentors[indexes[1]]; - return [student, mentor]; + const nullCheck = (element) => element === null; + if(pairsByIndex.some(nullCheck) === true) { + process.exit(1) + } + else + {return [student, mentor];} + }); + console.log(pairs); diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 3c02135..175e4dc 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,8 +9,14 @@ 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 safeLevels(arr) { + const convert = arr.map(function(level) { + return (parseFloat(level)) +}) +const levels = convert.filter(function(n) { + return n > 19.5 && n < 23.5; +}) +return `"${levels[0]}%"` } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index d900323..04512d3 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,8 +10,8 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function bushChecker(bush) { + if } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index f99891a..7ba44c9 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,10 +8,44 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { - +function colonisers(stayFamily) { + const stay = stayFamily.filter(function(name) { + if (name.split(" ")[1] === "family") { + return name[0] === "A"; + } + }); + return stay; } +// function colonisers(stayFamily) { + +// const stay = stayFamily.filter(function (name) { + +// if (name.split(" ")[1] === "family") { + +// return name[0] === "A"; + +// } + +// }); + +// return stay; + +// } + + + +function colonisers(stayFamily) { + + const stay = stayFamily.filter(function (name) { + + return name[0] === "A" && name.split(" ")[1] === "family"; + + }); + + return stay; + +} /* ======= TESTS - DO NOT MODIFY ===== */ const voyagers = [ diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 57b3d53..1bd6e03 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -23,7 +23,15 @@ PasswordValidationResult= [false, false, false, false, true] */ function validatePasswords(passwords) { - + const validate = passwords.map(function(valid) { + valid.length >= 5 && + valid.split("").find(letter => letter >= "A" && letter <= "Z") && + valid.split("").find(letter => letter >= "a" && letter <= "z") && + valid.split("").find(letter => letter >= 0 && letter <= 9) && + valid.split("").find(letter => letter["!", "#", "$", "%", "."]) + }) + console.log(validate); + return validate; } /* ======= TESTS - DO NOT MODIFY ===== */ From e5715c38abaf7f6784a63411f59ad07d6c0f37cf Mon Sep 17 00:00:00 2001 From: edksam Date: Mon, 6 Jul 2020 02:30:09 +0100 Subject: [PATCH 09/11] Up to No 7 done. --- week-3/2-mandatory/2-bush-berries.js | 40 ++++++++++++++++------ week-3/2-mandatory/4-eligible-students.js | 12 +++++-- week-3/2-mandatory/7-password-validator.js | 21 +++++++----- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index 04512d3..79ae250 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -11,7 +11,14 @@ */ function bushChecker(bush) { - if + const safeToEat = bush.every(function(pinky) { + return pinky === "pink"; + }) + if (safeToEat) { + return "Bush is safe to eat from" + } else { + return "Toxic! Leave bush alone!" + } } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -19,16 +26,27 @@ function bushChecker(bush) { let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"] let bushBerryColours2 = ["pink", "pink", "pink", "pink"] -function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } +const util = require('util'); + +function test(test_name, actual, expected) { + let status; + if (actual === expected) { + status = "PASSED"; + } else { + status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; + } - console.log(`${test_name}: ${status}`); + 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" +); \ No newline at end of file diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 6424b01..4a83842 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,9 +7,15 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { - -} +function eligibleStudents(attendance) { + const attended8 = attendances.filter(function(n){ + return n[1] >= 8; + }); + const names = attended8.map(function(name) { + return name[0]; + }) + return names; + } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 1bd6e03..5a22234 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -10,7 +10,7 @@ Passwords must - Have English uppercase letters (A-Z) - Have English lowercase letters (a-z) - Have numbers (0-9) -- Have non-alphanumeric symbols ("!", "#", "$", "%", ".") +- Have non-alphanumeric symbols ("!", "#", "$", "%", ".", "*", "&") Passwords must not be any previous password in the passwords array. @@ -24,15 +24,18 @@ PasswordValidationResult= [false, false, false, false, true] function validatePasswords(passwords) { const validate = passwords.map(function(valid) { - valid.length >= 5 && - valid.split("").find(letter => letter >= "A" && letter <= "Z") && - valid.split("").find(letter => letter >= "a" && letter <= "z") && - valid.split("").find(letter => letter >= 0 && letter <= 9) && - valid.split("").find(letter => letter["!", "#", "$", "%", "."]) + return valid.length >= 5 && + valid.split("").some(letter => letter >= "A" && letter <= "Z") && + valid.split("").some(letter => letter >= "a" && letter <= "z") && + valid.split("").some(letter => letter >= 0 && letter <= 9) && + // valid.split("").some(letter => "!", "#", "$", "%", ".", "*", "&") + valid.split("").some(function(c) { + !c.includes("!", "#", "$", "%", ".", "*", "&") }) - console.log(validate); - return validate; -} + }) + + return validate; + } /* ======= TESTS - DO NOT MODIFY ===== */ From 88116cd7d91cc684e68c41038075d1fe2e62902e Mon Sep 17 00:00:00 2001 From: edksam Date: Mon, 6 Jul 2020 22:51:01 +0100 Subject: [PATCH 10/11] No 7 done --- week-3/2-mandatory/7-password-validator.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 5a22234..364247b 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -23,19 +23,15 @@ PasswordValidationResult= [false, false, false, false, true] */ function validatePasswords(passwords) { - const validate = passwords.map(function(valid) { - return valid.length >= 5 && - valid.split("").some(letter => letter >= "A" && letter <= "Z") && - valid.split("").some(letter => letter >= "a" && letter <= "z") && - valid.split("").some(letter => letter >= 0 && letter <= 9) && - // valid.split("").some(letter => "!", "#", "$", "%", ".", "*", "&") - valid.split("").some(function(c) { - !c.includes("!", "#", "$", "%", ".", "*", "&") - }) - }) - - return validate; - } + let passwordCheck = passwords.map((pass, index, array) => { + if(pass.length >= 5 && /[A-Z]/.test(pass) && /[a-z]/.test(pass) && /[0-9]/.test(pass) && /[!#$%.*&]/.test(pass) && array.indexOf(pass) === index){ + return true; + }else{ + return false; + } + }); + return passwordCheck; +} /* ======= TESTS - DO NOT MODIFY ===== */ From ef7ef2980868626517f22cc04c6ea837e05f6ade Mon Sep 17 00:00:00 2001 From: edksam Date: Tue, 7 Jul 2020 01:18:36 +0100 Subject: [PATCH 11/11] final edit --- week-3/2-mandatory/1-oxygen-levels.js | 35 +++++++++++++++++-------- week-3/2-mandatory/5-journey-planner.js | 15 ++++++++++- week-3/2-mandatory/6-lane-names.js | 7 +++-- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 175e4dc..6eaaed6 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -13,34 +13,47 @@ function safeLevels(arr) { const convert = arr.map(function(level) { return (parseFloat(level)) }) +console.log(convert); const levels = convert.filter(function(n) { return n > 19.5 && n < 23.5; }) -return `"${levels[0]}%"` +return `${levels[0]}%` } + /* ======= TESTS - DO NOT MODIFY ===== */ -const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"] -const oxygenLevels2 = ["30.8%", "23.5%", "18.8%", "19.5%", "20.2%", "31.6%"] +const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"]; +const oxygenLevels2 = ["30.8%", "23.5%", "18.8%", "19.5%", "20.2%", "31.6%"]; +const oxygenLevels3 = ["200%", "21.1%"]; + +const util = require('util'); -function test(test_name, expr) { +function test(test_name, actual, expected) { let status; - if (expr) { - status = "PASSED"; + if (actual === expected) { + status = "PASSED"; } else { - status = "FAILED"; + status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; } - + console.log(`${test_name}: ${status}`); } test( - "safeLevels function works - case 2", - safeLevels(oxygenLevels1) === "19.9%" + "safeLevels function works - case 1", + safeLevels(oxygenLevels1), + "19.9%" ); test( "safeLevels function works - case 2", - safeLevels(oxygenLevels2) === "20.2%" + safeLevels(oxygenLevels2), + "20.2%" +); + +test( + "safeLevels function works - case 3", + safeLevels(oxygenLevels3), + "21.1%" ); \ No newline at end of file diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 53499c3..c2eb3a9 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,8 +7,21 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { +function journeyPlanner(locations, transportMode) { + const transportLoc = locations.filter(function (transport) { + + return transport.includes(transportMode); + + }); + + const locName = transportLoc.map(function (loc) { + + return loc[0]; + + }); + + return locName; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index eddfe44..df2bee7 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,8 +4,11 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { - +function getLanes(arr) { + const streetNames = arr.filter(function (names) { + return names.includes("Lane"); + }); + return streetNames; } /* ======= TESTS - DO NOT MODIFY ===== */