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

Mandatory #84

Open
wants to merge 1 commit 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
6 changes: 5 additions & 1 deletion week-3/1-exercises/A-array-find/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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 @@ -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];
});

Expand Down
11 changes: 9 additions & 2 deletions week-3/1-exercises/C-array-every/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 3 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,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"];
Expand Down
33 changes: 33 additions & 0 deletions week-3/1-exercises/E-array-map/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
58 changes: 30 additions & 28 deletions week-3/2-mandatory/1-oxygen-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,46 @@ 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 ===== */

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%");
14 changes: 12 additions & 2 deletions week-3/2-mandatory/2-bush-berries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===== */
Expand Down
9 changes: 8 additions & 1 deletion week-3/2-mandatory/3-space-colonies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
16 changes: 13 additions & 3 deletions week-3/2-mandatory/4-eligible-students.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
13 changes: 12 additions & 1 deletion week-3/2-mandatory/5-journey-planner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
9 changes: 6 additions & 3 deletions week-3/2-mandatory/6-lane-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===== */
Expand Down
38 changes: 37 additions & 1 deletion week-3/2-mandatory/7-password-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===== */
Expand Down