diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index d7fd51f..1f7b837 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -7,7 +7,12 @@ var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; -var longNameThatStartsWithA = findLongNameThatStartsWithA(names); +var longNameThatStartsWithA = names.find(findLongNameThatStartsWithA); + + +function findLongNameThatStartsWithA(name) { + return name.length > 7 && name[0] === "A"; +} 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..964f06e 100644 --- a/week-3/1-exercises/B-array-some/exercise.js +++ b/week-3/1-exercises/B-array-some/exercise.js @@ -16,6 +16,9 @@ var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; var pairs = pairsByIndex.map(function(indexes) { + if(indexes === null) { + process.exit(1); + } var student = students[indexes[0]]; var mentor = mentors[indexes[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..884c01a 100644 --- a/week-3/1-exercises/C-array-every/exercise.js +++ b/week-3/1-exercises/C-array-every/exercise.js @@ -5,7 +5,7 @@ var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; var group = ["Austine", "Dany", "Swathi", "Daniel"]; -var groupIsOnlyStudents; // complete this statement +var groupIsOnlyStudents = group.includes(students); // complete this statement if (groupIsOnlyStudents) { console.log("The group contains 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..aedf402 100644 --- a/week-3/1-exercises/D-array-filter/exercise.js +++ b/week-3/1-exercises/D-array-filter/exercise.js @@ -8,7 +8,10 @@ var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -var pairsByIndex; // Complete this statement +function isNumber(obj) { + return obj !== undefined && typeof (obj) === 'number' && !isNaN(obj) +} +var pairsByIndex = pairsByIndexRaw.filter(isNumber); // 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..33d835c 100644 --- a/week-3/1-exercises/E-array-map/exercise.js +++ b/week-3/1-exercises/E-array-map/exercise.js @@ -3,3 +3,22 @@ var numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; +function multiply100(number) { + return number * 100; +} + +var numbersBy100 = numbers.map(multiply100); + +var numbersBy100 = numbers.map(function multiply100(number) { + return number * 100; +}); + +var numbersBy100 = numbers.map(function (number) { + return number * 100; +}); + +var numbersBy100 = numbers.map(number => { + return number * 100; +}); + +var numbersBy100 = numbers.map(number => number * 100); \ No newline at end of file diff --git a/week-3/1-exercises/F-array-forEach/exercise.js b/week-3/1-exercises/F-array-forEach/exercise.js index e83e2df..6f17c5c 100644 --- a/week-3/1-exercises/F-array-forEach/exercise.js +++ b/week-3/1-exercises/F-array-forEach/exercise.js @@ -9,6 +9,18 @@ var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; +function printFizzBuzz (number) { + if(number % 3 === 0 && number % 5 === 0) { + return "FizzBuzz"; + } else if(number % 3 === 0) { + return "Fizz"; + } else if(number % 5=== 0) { + return "Buzz"; + } return number; +} +arr.map(printFizzBuzz).forEach(index => console.log(index)); + + /* EXPECTED OUTPUT */ /* diff --git a/week-3/1-exercises/G-array-methods/exercise.js b/week-3/1-exercises/G-array-methods/exercise.js index 44e9c80..b16182b 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..dd87089 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 = mentors.concat(students); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/H-array-methods-2/exercise.js b/week-3/1-exercises/H-array-methods-2/exercise.js index d36303b..b31cd58 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise.js +++ b/week-3/1-exercises/H-array-methods-2/exercise.js @@ -15,8 +15,8 @@ var everyone = [ "Swathi" ]; -var firstFive; // complete this statement -var lastFive; // complete this statement +var firstFive = everyone.slice(0, 5); // complete this statement +var lastFive = everyone.slice(2, 7); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/H-array-methods-2/exercise2.js b/week-3/1-exercises/H-array-methods-2/exercise2.js index b7be576..d4f7c2c 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise2.js +++ b/week-3/1-exercises/H-array-methods-2/exercise2.js @@ -7,7 +7,11 @@ Tip: use the string method .split() and the array method .join() */ -function capitalise(str) {} +function capitalise(str) { + let firstLetter = str.split(0,1); + firstLetter.toUpperCase(); +return firstLetter.join(); +} /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/H-array-methods-2/exercise3.js b/week-3/1-exercises/H-array-methods-2/exercise3.js index 82e9dd8..75a6b76 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise3.js +++ b/week-3/1-exercises/H-array-methods-2/exercise3.js @@ -7,7 +7,7 @@ var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; function isInUK(country) { - return; // complete this statement + return ukNations.includes(country); // complete this statement } /* diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index f9d745f..e85681b 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,7 +9,19 @@ 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 safeLevels() { +function findRightPlanet (oxygenLevelOfPlanet) { + if (parseFloat(oxygenLevelOfPlanet) > 19.50 && parseFloat(oxygenLevelOfPlanet) < 23.50) { + + return `${oxygenLevelOfPlanet}%`; + } + else { +return; + } +} + +function safeLevels(oxygenLevel) { +return oxygenLevel.find(findRightPlanet); + } diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index aca45ad..66ef591 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -9,11 +9,20 @@ Use the tests to confirm which message to return */ - -function bushChecker() { - +function checkColourPink(berryColour) { +if(berryColour === "pink") { + return true; +} } +function bushChecker(allBushBerryColours) { +let colourResult = allBushBerryColours.every(checkColourPink); +if(colourResult === true) { + 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"] diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index 239eddd..5fa18a6 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,10 +8,16 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { +//filter to remove non family and non A start +function colonisers(voyagersArray) { + return voyagersArray.filter(function(voyagerName) { + return voyagerName.startsWith("A") && voyagerName.includes("family"); + }) } + + /* ======= 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..296b3aa 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,9 +7,17 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { +//nested array [0] name [1] attendance, return array with just index [0] if [1] is >= 8 +function eligibleStudents(attendancesArray) { + let namesArray = []; + for(let i= 0; i < attendancesArray.length; i++) { + if (attendancesArray[i][1] >= 8) { + namesArray.push(attendancesArray[i][0]); + } + } return namesArray; +}; + -} /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 816637d..c50cd4a 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -6,10 +6,16 @@ NOTE: only the names should be returned, not the means of transport. */ - -function journeyPlanner() { +// return[0] index value if incudes string "transport" +function journeyPlanner(londonLocationsArray, transportMethod) { + let locationsAvailableArray =[]; +for(let i = 0; i < londonLocationsArray.length; i++) { + if (londonLocationsArray[i].includes(transportMethod)) { + locationsAvailableArray.push(londonLocationsArray[i][0]); + } + } return locationsAvailableArray; + } - /* ======= 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..b8bf309 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,8 +4,13 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { + function checkLanes(streetNameAsString) { + return streetNameAsString.includes("Lane"); + } + +function getLanes(streetNamesArray) { + return streetNamesArray.filter(checkLanes); } /* ======= 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 8f9e597..45eba65 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -22,8 +22,53 @@ PasswordValidationResult= [false, false, false, false, true] */ -function validatePasswords(passwords) { +function fiveOrMoreCharacters(passwordString) { + return passwordString.length >= 5; +} + + +function containsUpperCase(passwordString) { + let regex = /[A-Z]/; + return regex.test(passwordString); +} + +function containsLowerCase(passwordString) { + let regex = /[a-z]/; + return regex.test(passwordString); +} +function containsNumbers(passwordString) { + let regex = /[0-9]/; + return regex.test(passwordString); +} + +function containsSymbols(passwordString) { + let regex = /[!#$%.*&]/; + return regex.test(passwordString); +} + +function validatePasswords(passwordsArray) { + return passwordsArray.map((passwordString, index, passwordsArray) => { + let notRepeated = true; + for (let j = 0; j < passwordsArray.length; j++) { + if (index !== j) { + if (passwordsArray[index] === passwordsArray[j]) { + notRepeated = false; + if (index < j) { notRepeated = true } + break; + } + } + if (!notRepeated) { + break; + } + } + return fiveOrMoreCharacters(passwordString) + && containsUpperCase(passwordString) + && containsLowerCase(passwordString) + && containsNumbers(passwordString) + && containsSymbols(passwordString) + && notRepeated + }) } /* ======= TESTS - DO NOT MODIFY ===== */