Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

London_10-Saliha_Popal/JavaScript-Core-1-Coursework-Week4 #247

Open
wants to merge 1 commit into
base: main
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
5 changes: 3 additions & 2 deletions 1-exercises/A-array-find/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ let names = [
"Ahmed",
];

let longNameThatStartsWithA = findLongNameThatStartsWithA(names);
let longNameThatStartsWithA = names.find(name => name.startsWith("A") && name.length > 7);
console.log(longNameThatStartsWithA);


console.log(longNameThatStartsWithA);

/* EXPECTED OUTPUT */
// "Alexandra"
8 changes: 8 additions & 0 deletions 1-exercises/B-array-some/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ let pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]];
let students = ["Islam", "Lesley", "Harun", "Rukmini"];
let mentors = ["Daniel", "Irina", "Mozafar", "Luke"];

function isNull(pair){
return pair === null;
}

if(pairsByIndex.some(isNull)){
process.exit(1);
}

let pairs = pairsByIndex.map(function (indexes) {
let student = students[indexes[0]];
let mentor = mentors[indexes[1]];
Expand Down
5 changes: 2 additions & 3 deletions 1-exercises/C-array-every/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
let students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"];
let group = ["Austine", "Dany", "Swathi", "Daniel"];

let groupIsOnlyStudents; // complete this statement

if (groupIsOnlyStudents) {
let groupIsOnlyStudents = group.every(student => students.includes(student)); // complete this statement
if(groupIsOnlyStudents){
console.log("The group contains only students");
} else {
console.log("The group does not contain only students");
Expand Down
8 changes: 7 additions & 1 deletion 1-exercises/D-array-filter/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@

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

let pairsByIndex; // Complete this statement

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

let pairsByIndex = pairsByIndexRaw.filter(function(pair){
return Array.isArray(pair) && pair.length === 2 && typeof pair[0] === "number" && typeof pair[1] === "number" && pair[0] < students.length && pair[1] < mentors.length;
}); // Complete this statement

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

let pairs = pairsByIndex.map(function (indexes) {
let student = students[indexes[0]];
let mentor = mentors[indexes[1]];
Expand Down
4 changes: 3 additions & 1 deletion 1-exercises/E-array-map/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

let numbers = [0.1, 0.2, 0.3, 0.4, 0.5];

let numbersMultipliedByOneHundred; // complete this statement
let numbersMultipliedByOneHundred = numbers.map(function(numbersMultipliedByOneHundred){
return numbersMultipliedByOneHundred * 100;
}); // complete this statement

console.log(numbersMultipliedByOneHundred);

Expand Down
12 changes: 12 additions & 0 deletions 1-exercises/F-array-forEach/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@

let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];

arr.forEach(num => {
if (num % 3 === 0){
console.log("Fizz");
} else if(num % 5 === 0){
console.log("Buzz");
}else if(num % 3 === 0 && num % 5 === 0) {
console.log("Fizzbuzz");
} else{
console.log(num);
}
});

/* EXPECTED OUTPUT */

/*
Expand Down
2 changes: 1 addition & 1 deletion 1-exercises/G-array-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

let numbers = [3, 2, 1];
let sortedNumbers; // complete this statement
let sortedNumbers = numbers.sort(); // complete this statement

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
4 changes: 2 additions & 2 deletions 1-exercises/H-array-methods-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ let everyone = [
"Swathi",
];

let firstFive; // complete this statement
let lastFive; // complete this statement
let firstFive = everyone.slice(0, 5); // complete this statement
let lastFive = everyone.slice(2, 6); // complete this statement

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
22 changes: 20 additions & 2 deletions 1-exercises/H-array-methods-2/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,30 @@
Tip: use the string method .split() and the array method .join()
*/

function capitalise(str) {}
function capitalise(str) {
// return str.charAt(0).toUpperCase() + str.slice(1);
const chars = str.split("");
console.log(chars[0].join(""));
}

function capitalise(str) {
// split the string into an array of words
const words = str.split(" ");

// iterate over each word and capitalise the first letter
const capitalisedWords = words.map((word) => {
return word.charAt(0).toUpperCase() + word.slice(1);
});

// join the capitalised words back into a string and return it
return capitalisedWords.join(" ");
}


/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
let name = "daniel";
const name = "daniel";

console.log(capitalise(name));
console.log(capitalise("hello"));
Expand Down
9 changes: 8 additions & 1 deletion 1-exercises/H-array-methods-2/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
let ukNations = ["Scotland", "Wales", "England", "Northern Ireland"];

function isInUK(country) {
return; // complete this statement
for (let ukNation of ukNations){
const isInUK = ukNations.includes(country);
return isInUK;
}; // complete this statement
}
const isFrance = isInUK("France");
const isRepublicOfIreland = isInUK("Republic of Ireland");
const isEngland = isInUK("England");


/*
DO NOT EDIT BELOW THIS LINE
Expand Down
5 changes: 4 additions & 1 deletion 1-exercises/I-string-replace/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
let story =
"I like dogs. One day I went to the park and I saw 10 dogs. It was a great day.";

let result = story.replace("", "");
// let result = story.replace("dogs", "cats").replace("day", "night").replace("10", "100000").replace("great", "brilliant"); why not correct

let result = story.replace(/dogs/g, "cats").replace(/day/g, "night").replace(/10/g, "100000").replace(/great/g, "brilliant");


/* EXPECTED OUTPUT */

Expand Down
6 changes: 4 additions & 2 deletions 2-mandatory/1-create-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ Write a function that:
- Accepts an array as a parameter.
- Returns a new array containing the first five elements of the passed array.
*/
function first5() {
function first5(array) {
return array.slice(0, 5);
}

/*
Write a function that:
- Accepts an array as a parameter.
- Returns a new array containing the same elements, except sorted.
*/
function sortArray() {
function sortArray(array) {
return array.some();
}

/*
Expand Down
8 changes: 6 additions & 2 deletions 2-mandatory/2-oxygen-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

Some string methods that might help you here are .replace() and .substring().
*/

function findSafeOxygenLevel() {}
function isSafeOxygenLevel(oxygenLevel){
return parseFloat(oxygenLevel)>19.5 && parseFloat(oxygenLevel)<23.5;
}
function findSafeOxygenLevel(oxygenLevels) {
return oxygenLevels.find(isSafeOxygenLevel);
}

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

Expand Down
7 changes: 7 additions & 0 deletions 2-mandatory/3-bush-berries.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
The space travellers have safely landed and are foraging for food in the natural wildlife.

Expand Down Expand Up @@ -25,6 +26,12 @@ function isBushSafe(berryArray) {
//Write your code here
}

/*if (isVegetarian) {
return "Macaroni and Cheese";
} else {
return "Steak and Chips";
}*/

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

test("isBushSafe finds toxic busy", () => {
Expand Down
1 change: 1 addition & 0 deletions 3-extra/1-card-vailidator.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ These are the requirements your project needs to fulfill:
- Use `node` from the command line to test if your code works as expected.

Good luck!