diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index d7fd51f..4419033 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -6,8 +6,12 @@ // write your code here var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; +function findLongNameThatStartsWithA(names){ + return names.length > 7 && names.charAt(0) === "A"; +} -var longNameThatStartsWithA = findLongNameThatStartsWithA(names); + +var longNameThatStartsWithA = names.find(findLongNameThatStartsWithA); 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..783b028 100644 --- a/week-3/1-exercises/B-array-some/exercise.js +++ b/week-3/1-exercises/B-array-some/exercise.js @@ -18,6 +18,9 @@ var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; var pairs = pairsByIndex.map(function(indexes) { var student = students[indexes[0]]; var mentor = mentors[indexes[1]]; + if (pairsByIndex[indexes] == null){ + process.exit(1); + } return [student, mentor]; }); diff --git a/week-3/1-exercises/C-array-every/exercise.js b/week-3/1-exercises/C-array-every/exercise.js index b515e94..029ad0f 100644 --- a/week-3/1-exercises/C-array-every/exercise.js +++ b/week-3/1-exercises/C-array-every/exercise.js @@ -3,11 +3,18 @@ */ var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; + // var group = ["Omar", "Austine", "Dany", "Lesley"]; // for test var group = ["Austine", "Dany", "Swathi", "Daniel"]; -var groupIsOnlyStudents; // complete this statement +function isGroupStudents(name){ -if (groupIsOnlyStudents) { + return students.includes(name); + +} + +var groupIsOnlyStudents = group.every(isGroupStudents) // complete this statement + +if (groupIsOnlyStudents === true) { console.log("The group contains only students"); } else { console.log("The group does not contain only students"); diff --git a/week-3/1-exercises/D-array-filter/exercise.js b/week-3/1-exercises/D-array-filter/exercise.js index 6e32cc6..f9a1086 100644 --- a/week-3/1-exercises/D-array-filter/exercise.js +++ b/week-3/1-exercises/D-array-filter/exercise.js @@ -8,7 +8,9 @@ var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -var pairsByIndex; // Complete this statement +var pairsByIndex = pairsByIndexRaw.filter(function (pairsByIndexRaw){ + return pairsByIndexRaw[0,[0]]; +}); // Complete this statement var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; diff --git a/week-3/1-exercises/E-array-map/exercise.js b/week-3/1-exercises/E-array-map/exercise.js index 2835e92..c67b218 100644 --- a/week-3/1-exercises/E-array-map/exercise.js +++ b/week-3/1-exercises/E-array-map/exercise.js @@ -2,4 +2,37 @@ // Write multiple solutions using different syntax (as shown in the README) var numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; +function multiplcation(numbers){ + return numbers * 100; +} +var multipling = numbers.map(multiplcation); +console.log(multipling); +///////////////////////////////////////////// + +var multipling2 = numbers.map(function multiplcation2(numbers){ + return numbers * 100; +}); +console.log(multipling2); + +///////////////////////////////////////////// + +var multipling3 = numbers.map(function (numbers) { + return numbers * 100; +}); +console.log(multipling3); + +///////////////////////////////////////////// + + +var multipling4 = numbers.map( numbers => { + return numbers * 100; +}); +console.log(multipling4); + +///////////////////////////////////////////// + +var multipling5 = numbers.map(numbers => numbers * 100 +); + +console.log(multipling5); diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index f9d745f..33532bc 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -8,10 +8,22 @@ To be safe to land on, a planet needs to have an Oxygen level between 19.5% and Write a function that finds the first safe oxygen level in the array - Oxygen between 19.5% and 23.5% */ +function findRightPlanet(oxygenLevelOfPlanet) { + if (parseFloat(oxygenLevelOfPlanet) > 19.50 && parseFloat(oxygenLevelOfPlanet) < 23.50) { + return `${oxygenLevelOfPlanet}%`; + } + else { + return; + } +} +function safeLevels(oxygenLevel) { + return oxygenLevel.find(findRightPlanet); +} + + + -function safeLevels() { -} /* ======= TESTS - DO NOT MODIFY ===== */ @@ -19,33 +31,23 @@ 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'); +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}`); + 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}`); } -test( - "safeLevels function works - case 1", - safeLevels(oxygenLevels1), - "19.9%" -); - -test( - "safeLevels function works - case 2", - safeLevels(oxygenLevels2), - "20.2%" -); - -test( - "safeLevels function works - case 3", - safeLevels(oxygenLevels3), - "21.1%" -); +test("safeLevels function works - case 1", safeLevels(oxygenLevels1), "19.9%"); + +test("safeLevels function works - case 2", safeLevels(oxygenLevels2), "20.2%"); + +test("safeLevels function works - case 3", safeLevels(oxygenLevels3), "21.1%"); diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index aca45ad..d38cde6 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,8 +10,18 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function checkColourPink(berryColour) { + if (berryColour === "pink") { + return true; + } +} +function bushChecker(allBerryColours) { + let result = allBerryColours.every(checkColourPink); + if (result === true) { + return "Bush is safe to eat from"; + } else { + return "Toxic! Leave bush alone!"; + } } /* ======= 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 239eddd..c9005a5 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -7,11 +7,18 @@ NOTE: don't include any element that is not a "family". */ +function filteringNames(names){ + return names.includes("family") && names.charAt(0) === "A"; +} -function colonisers() { +function colonisers(voyagers) { + let result = voyagers.filter(filteringNames); + return result; + } + /* ======= TESTS - DO NOT MODIFY ===== */ const voyagers = [ diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index d8fe052..1072b40 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -4,13 +4,23 @@ Create a function which: - Accepts an array which contains all the students' names and their attendance counts (see tests to confirm how this data will be structured) - - Returns an array containing only the names of the who have attended AT LEAST 8 classes + - Returns an array containing only the names of those who have attended AT LEAST 8 classes */ -function eligibleStudents() { - + function eligibleStudents(attendances) { + let newAttendances =[]; + for (i = 0; i < attendances.length; i++){ + if (attendances[i][1] >= 8){ + newAttendances.push(attendances[i][0]); + } + } + + return newAttendances; } + + + /* ======= TESTS - DO NOT MODIFY ===== */ const attendances = [ diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 816637d..b5c4624 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,9 +7,20 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { +function journeyPlanner(londonLocations, meansOfTransport ) { + let availableLocations = []; + for (i = 0; i < londonLocations.length; i++){ + if (londonLocations[i].includes(meansOfTransport)){ + availableLocations.push(londonLocations[i][0]); + } + + } + + return availableLocations; + } + /* ======= TESTS - DO NOT MODIFY ===== */ const londonLocations = [ diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index ef4e1c5..719e04c 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -3,9 +3,12 @@ Write a function that will return all street names which contain 'Lane' in their name. */ - -function getLanes() { - +function lane(input){ + return input.includes("Lane"); +} +function getLanes(streetNames) { + let result = streetNames.filter(lane); + return result; } /* ======= 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 d408ba6..927f373 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -21,9 +21,45 @@ Expected Result: PasswordValidationResult= [false, false, false, false, true] */ +function PasswordLength(inputPassword) { + return inputPassword.length >= 5; +} -function validatePasswords(passwords) { +function containsUpperCase(inputPassword) { + let regex = /[A-Z]/; + return regex.test(inputPassword); +} +function containsLowerCase(inputPassword) { + let regex = /[a-z]/; + return regex.test(inputPassword); +} +function containsNumbers(inputPassword) { + let regex = /[0-9]/; + return regex.test(inputPassword); +} +function containsSymbols(inputPassword) { + let regex = /[!#$%.*&]/; + return regex.test(inputPassword); +} + +function isThereADuplicate(inputPassword) { + + for (i = 0; i < inputPassword.length; i++){ + if (inputPassword === inputPassword[i + 1]){ + return false; + } return true; + } + +} +function validatePasswords(inputPassword) { + return inputPassword.map(inputPassword => PasswordLength(inputPassword) + && containsUpperCase(inputPassword) + && containsLowerCase(inputPassword) + && containsNumbers(inputPassword) + && containsSymbols(inputPassword) + && isThereADuplicate(inputPassword) + ); } /* ======= TESTS - DO NOT MODIFY ===== */