Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.
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: 5 additions & 2 deletions week-3/1-exercises/A-array-find/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
*/

// write your code here

function findLongNameThatStartsWithA(names)
{
return names.length > 7;
}
var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"];

var longNameThatStartsWithA = findLongNameThatStartsWithA(names);
var longNameThatStartsWithA = names.find(findLongNameThatStartsWithA);

console.log(longNameThatStartsWithA);

Expand Down
15 changes: 12 additions & 3 deletions week-3/1-exercises/B-array-some/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]];
// https://nodejs.org/api/process.html#process_process_exit_code
// process.exit(1);


var students = ["Islam", "Lesley", "Harun", "Rukmini"];
var mentors = ["Daniel", "Irina", "Mozafar", "Luke"];

var mentors = ["Daniel", "Irina", "Mozafar", "Luke"];
function isNull(x) {
return x === null;
}
var pairs = pairsByIndex.map(function(indexes) {
if(pairsByIndex.some(isNull)) {
process.exit(1);
}

var student = students[indexes[0]];
var mentor = mentors[indexes[1]];
return [student, mentor];
return [student, mentor];

});

console.log(pairs);

5 changes: 4 additions & 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,10 @@
var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"];
var group = ["Austine", "Dany", "Swathi", "Daniel"];

var groupIsOnlyStudents; // complete this statement
function containsOnlyStudents(name) {
return name < students;
}
var groupIsOnlyStudents = group.every(containsOnlyStudents); // complete this statement

if (groupIsOnlyStudents) {
console.log("The group contains only students");
Expand Down
14 changes: 11 additions & 3 deletions week-3/1-exercises/D-array-filter/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@

var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"];

var pairsByIndex; // Complete this statement
var pairsByIndex = pairsByIndexRaw.filter(function(i) {
if (typeof(i) !== "object" || i === null) {
return false;}
else if (i.length !== 2) {
return false;}
else {
return true;}
});
// Complete this statement

var students = ["Islam", "Lesley", "Harun", "Rukmini"];
var mentors = ["Daniel", "Irina", "Mozafar", "Luke"];

var pairs = pairsByIndex.map(function(indexes) {
var pairs = pairsByIndex.map(function(indexes) {;
var student = students[indexes[0]];
var mentor = mentors[indexes[1]];
return [student, mentor];
});

console.log(pairs);
console.log(pairsByIndex.forEach(x => console.log(x)));
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 multiplyByHundred(num) {
return num * 100;
}
var result = numbers.map(multiplyByHundred);
console.log(result);

var answer = numbers.map(function byHundred(number) {
return number * 100;
});

console.log(answer);

var answer = numbers.map(number => {
return number * 100;
});
console.log(answer);

var result = numbers.map(number => number * 100);
console.log(result);
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 @@ -8,6 +8,18 @@
*/

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
arr.forEach(function(num){
if (num % 3 === 0 && num % 5 === 0) {
console.log ("FizzBuzz");
} else if (num % 5 === 0){
console.log ("Buzz");
}
else if (num % 3 === 0) {
console.log ("Fizz");

} else
console.log(num);
});

/* 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
14 changes: 13 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,19 @@
Tip: use the string method .split() and the array method .join()
*/

function capitalise(str) {}
function capitalise(str)
{
str = str.split(" ");

for (var i = 0, x = str.length; i < x; i++) {
str[i] = str[i][0].toUpperCase() + str[i].substr(1);
}

return str.join(" ");
}




/*
DO NOT EDIT BELOW THIS LINE
Expand Down
5 changes: 3 additions & 2 deletions week-3/1-exercises/H-array-methods-2/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"];

function isInUK(country) {
return; // complete this statement
}
return ukNations.includes(country);
}; // complete this statement


/*
DO NOT EDIT BELOW THIS LINE
Expand Down
36 changes: 35 additions & 1 deletion week-3/2-mandatory/1-oxygen-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,51 @@ 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 safeLevels(oxygenLevels){

let safetyLevel = oxygenLevels.find(oxygenLevel =>{
let oxygenLevelNum = parseFloat(oxygenLevel);
// console.log(oxygenLevelNum > 19.5 && oxygenLevelNum < 23.5);
// console.log(oxygenLevelNum , 19.5 , oxygenLevelNum , 23.5);
if(oxygenLevelNum > 19.5 && oxygenLevelNum < 23.5){

return oxygenLevel;
}
})
return `${safetyLevel}`;
}

// function findSafelevels(safety){
// safety =
// if(safety > 19.5 && safety < 23.5)
// return safety.concat("%");
// }

// function safeLevels(a) {

// let newArray =[];
// let index;
// for (let i = 0; i < a.length; i++) {
// newArray[i] = a[i];


// }
// let found = newArray.find(findSafelevels);
// return found;
// }



/* ======= 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 { stringify } = require('querystring');

function test(test_name, actual, expected) {
let status;
Expand Down
14 changes: 13 additions & 1 deletion week-3/2-mandatory/2-bush-berries.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@
Use the tests to confirm which message to return
*/

function bushChecker() {

function bushChecker(arr) {
let Array =[];
let index;
for (let i = 0; i < arr.length; i++) {
Array[i] = arr[i];
}
for (var i = 0; i < arr.length; i++ ) {
if(Array[i] !== "pink"){
return 'Toxic! Leave bush alone!';
}}
return 'Bush is safe to eat from';


}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
11 changes: 10 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,19 @@
NOTE: don't include any element that is not a "family".
*/

function colonisers() {
function colonisers(voyager) {
let findColonisers = voyager.filter(coloniser => {

if (coloniser.includes("A") && coloniser.includes("family")){
return coloniser;
}
})
return findColonisers;
}




/* ======= TESTS - DO NOT MODIFY ===== */

const voyagers = [
Expand Down
12 changes: 11 additions & 1 deletion week-3/2-mandatory/4-eligible-students.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@
- Returns an array containing only the names of the who have attended AT LEAST 8 classes
*/

function eligibleStudents() {
function eligibleStudents(arr) {
let arrAttendance = arr.filter(function (attendance){
return attendance[1] >= 8;
});

const names = arrAttendance.map(function(loc) {
return loc[0];
});

return names;
}



/* ======= TESTS - DO NOT MODIFY ===== */

const attendances = [
Expand Down
10 changes: 9 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,17 @@
NOTE: only the names should be returned, not the means of transport.
*/

function journeyPlanner() {
function journeyPlanner(locations, modeOfTransportation) {
const transport = locations.filter(function(transportation) {
return transportation.includes(modeOfTransportation);
});
const NameOfLocation = transport.map(function(locationMode){
return locationMode[0];
});
return NameOfLocation;
}


/* ======= TESTS - DO NOT MODIFY ===== */

const londonLocations = [
Expand Down
10 changes: 9 additions & 1 deletion week-3/2-mandatory/6-lane-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
Write a function that will return all street names which contain 'Lane' in their name.
*/

function getLanes() {
function getLanes(myLanes) {
let findLanes = myLanes.filter(Lanes => {

if (Lanes.includes("Lane")){
return Lanes;
}
})
return findLanes;
}



/* ======= TESTS - DO NOT MODIFY ===== */

const streetNames = [
Expand Down
14 changes: 13 additions & 1 deletion week-3/2-mandatory/7-password-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,22 @@ Expected Result:
PasswordValidationResult= [false, false, false, false, true]

*/
// let meal = ["eggs", "eggs", "banana", "orange", "eggs"];



function validatePasswords(passwords) {
let newArray = [];
for (i=0; i<passwords.length;i++){
newArray[i]= passwords.indexOf(passwords[i]) === i && passwords[i].length>=5 && passwords[i].match(/[A-Z]/) !== null &&
passwords[i].match(/[a-z]/)!== null && passwords[i].match(/[0-9]/)!== null && passwords[i].match(/[!#$%.]/)!== null;
}
return newArray;
}




}

/* ======= TESTS - DO NOT MODIFY ===== */

Expand Down
2 changes: 1 addition & 1 deletion week-3/2-mandatory/8-codewars.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Today, you'll be using a platform called [CodeWars](https://codewars.com) to hel
- [opposite number](https://www.codewars.com/kata/opposite-number/train/javascript)
- [return negative](https://www.codewars.com/kata/return-negative/train/javascript)
- [hydrated](https://www.codewars.com/kata/keep-hydrated-1/train/javascript)
- [bonus](https://www.codewars.com/kata/do-i-get-a-bonus/train/javascript)
- [bonus](https://www.codewars.com/kata/convert-boolean-values-to-strings-yes-or-no/train/javascript)
- [remove string spaces](https://www.codewars.com/kata/remove-string-spaces/train/javascript)
- [remove first and last character](https://www.codewars.com/kata/remove-first-and-last-character/train/javascript)
- [string repeat](https://www.codewars.com/kata/string-repeat/train/javascript)
Expand Down
Loading