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

Glasgow6-Haroun-Alarabi- Javcript-Core-1-Coursework-Week4 #222

Open
wants to merge 2 commits 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
6 changes: 4 additions & 2 deletions 1-exercises/A-array-find/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ let names = [
"Karim",
"Ahmed",
];
function findLongNameThatStartsWithA(name){
return name.length >7 ;
}

let longNameThatStartsWithA = findLongNameThatStartsWithA(names);

let longNameThatStartsWithA = names.find(findLongNameThatStartsWithA);
console.log(longNameThatStartsWithA);

/* EXPECTED OUTPUT */
Expand Down
12 changes: 11 additions & 1 deletion 1-exercises/B-array-some/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@
*/

let pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]];
function checkNull (){
console.error('pairsByIndex have null value');
return process.exit(1);
}
let containNull = pairsByIndex.some(checkNull)
console.log(containNull);




// }
// If there is a null value in the array exit the program with the error code
// https://nodejs.org/api/process.html#process_process_exit_code
// process.exit(1);

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]];
return [student, mentor];
});

console.log(pairs);

6 changes: 5 additions & 1 deletion 1-exercises/C-array-every/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"];
let group = ["Austine", "Dany", "Swathi", "Daniel"];

let groupIsOnlyStudents; // complete this statement
let groupIsOnlyStudents = group.every(checkIfAllStudent) ; // complete this statement

if (groupIsOnlyStudents) {
console.log("The group contains only students");
Expand All @@ -16,3 +16,7 @@ if (groupIsOnlyStudents) {
/* EXPECTED RESULT */

// The group does not contain only students
function checkIfAllStudent(name) {
return students.includes(name) ;
}

10 changes: 8 additions & 2 deletions 1-exercises/D-array-filter/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

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

let pairsByIndex; // Complete this statement
let pairsByIndex = pairsByIndexRaw.filter(function isPairs(name){
return Array.isArray(name) && name.length === 2;
}); // Complete this statement

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

let pairs = pairsByIndex.map(function (indexes) {
Expand All @@ -21,6 +23,10 @@ let pairs = pairsByIndex.map(function (indexes) {

console.log(pairs);





/* EXPECTED RESULT

[ [ 'Islam', 'Luke' ], [ 'Lesley', 'Mozafar' ], [ 'Harun', 'Irina' ] ]
Expand Down
7 changes: 5 additions & 2 deletions 1-exercises/E-array-map/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// Write multiple solutions using different syntax (as shown in the README)

let numbers = [0.1, 0.2, 0.3, 0.4, 0.5];
let numbersMultipliedByOneHundred = numbers .map(function multiple(number) {
return number * 100;
});
console.log(numbersMultipliedByOneHundred);


let numbersMultipliedByOneHundred; // complete this statement

console.log(numbersMultipliedByOneHundred);

/* EXPECTED RESULT

Expand Down
20 changes: 17 additions & 3 deletions 1-exercises/F-array-forEach/exercise.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
/*
/*
Using .forEach() print the numbers 1 to 15, with some exceptions:
- For multiples of 3 print “Fizz” instead of the number
- For the multiples of 5 print “Buzz”.
- For multiples of 3 print “Fizz” instead of the number
- For the multiples of 5 print “Buzz”.
- For numbers which are multiples of both 3 and 5 print “FizzBuzz”

An array with numbers 1-15 has been provided.
*/

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




/* EXPECTED OUTPUT */

Expand Down
6 changes: 3 additions & 3 deletions 1-exercises/G-array-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/

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

/*
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */

console.log(sortedNumbers);

/*
/*
EXPECTED RESULT
---------------
[1, 2, 3]
Expand Down
6 changes: 3 additions & 3 deletions 1-exercises/G-array-methods/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
let mentors = ["Daniel", "Irina", "Rares"];
let students = ["Rukmini", "Abdul", "Austine", "Swathi"];

let everyone; // complete this statement
let everyone = mentors.concat(students);

/*
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */

console.log(everyone);

/*
/*
EXPECTED RESULT
---------------
["Daniel", "Irina", "Rares", "Rukmini", "Abdul", "Austine", "Swathi"]
Expand Down
8 changes: 4 additions & 4 deletions 1-exercises/H-array-methods-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ let everyone = [
"Swathi",
];

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

/*
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */

console.log(firstFive);
console.log(lastFive);

/*
/*
EXPECTED RESULT
---------------
["Daniel", "Irina", "Rares", "Rukmini", "Abdul"]
Expand Down
12 changes: 8 additions & 4 deletions 1-exercises/H-array-methods-2/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
/*
Array methods - .join()
-------------------------
Complete the capitalise function
Complete the capitalise function
It should return a string with the first letter in uppercase
For example, capitailise("hello") should return "Hello"
Tip: use the string method .split() and the array method .join()
*/

function capitalise(str) {}
function capitalise(str) {
let str1 = str.split('');
str1[0] = str1[0].toUpperCase() + str1[0].slice(1);
return str1.join('');
}

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

console.log(capitalise(name));
console.log(capitalise("hello"));

/*
/*
EXPECTED RESULT
---------------
Daniel
Expand Down
6 changes: 3 additions & 3 deletions 1-exercises/H-array-methods-2/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
let ukNations = ["Scotland", "Wales", "England", "Northern Ireland"];

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

/*
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
console.log(isInUK("France"));
console.log(isInUK("Republic of Ireland"));
console.log(isInUK("England"));

/*
/*
EXPECTED RESULT
---------------
false
Expand Down
11 changes: 7 additions & 4 deletions 1-exercises/I-string-replace/exercise.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
/*
/*
You are given a sentence contains a story.

Current it says
Current it says

"I like dogs. One day I went to the park and I saw 10 dogs. It was a great day."

Change the story using .replace() so that it says
Change the story using .replace() so that it says

"I like cats. One night I went to the park and I saw 100000 cats. It was a brilliant night."
*/

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(
"I like dogs. One day I went to the park and I saw 10 dogs. It was a great day.",
"I like cats. One night I went to the park and I saw 100000 cats. It was a brilliant night."
);

/* EXPECTED OUTPUT */

Expand Down
10 changes: 5 additions & 5 deletions 1-exercises/J-string-substring/exercise.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
/*
You are given an statement

You should remove the word "and dogs" by using substring
You should remove the word "and dogs" by using substring
*/

let statement = "I like programming and dogs";

statement = statement.substring();
statement = statement.substring(0,19);

console.log(statement);

/* EXPECTED OUTPUT
/* EXPECTED OUTPUT

"I like programming"

*/
8 changes: 5 additions & 3 deletions 1-exercises/J-string-substring/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
You are given an array with a list of names.

You should log only the peoples first names.
Expand All @@ -20,16 +20,18 @@ names[2] = names[2].substring();
names[3] = names[3].substring();
names[4] = names[4].substring();


names.forEach((name) => {
console.log(name);

});

/* EXPECTED OUTPUT
/* EXPECTED OUTPUT

"Tamzin"
"Jessica"
"Tony"
"Shae"
"Arron"

*/
8 changes: 4 additions & 4 deletions 1-exercises/J-string-substring/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
You are given an statement

You should remove the word "not" by using .substring() and log the result.
Expand All @@ -8,12 +8,12 @@

let statement = "I do not like programming";

let result = "";
let result = statement.substring(0, 5) + statement.substring(8);

console.log(result);

/* EXPECTED OUTPUT
/* EXPECTED OUTPUT

"I do like programming"

*/
Loading