Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Dan carter week 3 #76

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion week-3/1-exercises/A-array-find/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions week-3/1-exercises/B-array-some/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion week-3/1-exercises/C-array-every/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 4 additions & 1 deletion week-3/1-exercises/D-array-filter/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
19 changes: 19 additions & 0 deletions week-3/1-exercises/E-array-map/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
12 changes: 12 additions & 0 deletions week-3/1-exercises/F-array-forEach/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

/*
Expand Down
2 changes: 1 addition & 1 deletion week-3/1-exercises/G-array-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion week-3/1-exercises/G-array-methods/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions week-3/1-exercises/H-array-methods-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion week-3/1-exercises/H-array-methods-2/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion week-3/1-exercises/H-array-methods-2/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/*
Expand Down
14 changes: 13 additions & 1 deletion week-3/2-mandatory/1-oxygen-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);


}

Expand Down
15 changes: 12 additions & 3 deletions week-3/2-mandatory/2-bush-berries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
8 changes: 7 additions & 1 deletion week-3/2-mandatory/3-space-colonies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
12 changes: 10 additions & 2 deletions week-3/2-mandatory/4-eligible-students.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===== */

Expand Down
12 changes: 9 additions & 3 deletions week-3/2-mandatory/5-journey-planner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
7 changes: 6 additions & 1 deletion week-3/2-mandatory/6-lane-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===== */
Expand Down
47 changes: 46 additions & 1 deletion week-3/2-mandatory/7-password-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===== */
Expand Down