From 207741f97f9483a8a11beaf7805fb9422eb041d5 Mon Sep 17 00:00:00 2001
From: Zahraa <113244988+ZahraaTayyar@users.noreply.github.com>
Date: Sat, 17 Dec 2022 10:10:46 +0000
Subject: [PATCH 1/8] Started
---
1-exercises/A-array-find/exercise.js | 5 ++++-
1-exercises/C-array-every/exercise.js | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/1-exercises/A-array-find/exercise.js b/1-exercises/A-array-find/exercise.js
index 35902fed..27f40006 100644
--- a/1-exercises/A-array-find/exercise.js
+++ b/1-exercises/A-array-find/exercise.js
@@ -3,7 +3,10 @@
Using .find(), we'd like to find the first name which starts with A and is longer than 7 letters.
*/
-// write your code here
+function findLongNameThatStartsWithA(name) {
+ return name.find(name => name.length > 7 && name[0] === "A")
+}
+
let names = [
"Rakesh",
diff --git a/1-exercises/C-array-every/exercise.js b/1-exercises/C-array-every/exercise.js
index 347b9632..8980f463 100644
--- a/1-exercises/C-array-every/exercise.js
+++ b/1-exercises/C-array-every/exercise.js
@@ -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(member => students); // complete this statement
if (groupIsOnlyStudents) {
console.log("The group contains only students");
From 8880a121a106e256aaf373faff72fe75e70d49b4 Mon Sep 17 00:00:00 2001
From: ZahraaTayyar
Date: Tue, 21 Mar 2023 16:57:04 +0000
Subject: [PATCH 2/8] exercises completed
---
1-exercises/B-array-some/exercise.js | 9 +++++++++
1-exercises/C-array-every/exercise.js | 2 +-
1-exercises/D-array-filter/exercise.js | 6 ++++--
1-exercises/E-array-map/exercise.js | 4 ++--
1-exercises/F-array-forEach/exercise.js | 12 ++++++++++++
1-exercises/G-array-methods/exercise.js | 2 +-
1-exercises/G-array-methods/exercise2.js | 2 +-
1-exercises/H-array-methods-2/exercise.js | 4 ++--
1-exercises/H-array-methods-2/exercise2.js | 4 +++-
1-exercises/H-array-methods-2/exercise3.js | 2 +-
1-exercises/I-string-replace/exercise.js | 6 +++++-
1-exercises/J-string-substring/exercise.js | 2 +-
1-exercises/J-string-substring/exercise2.js | 10 +++++-----
1-exercises/J-string-substring/exercise3.js | 3 ++-
14 files changed, 49 insertions(+), 19 deletions(-)
diff --git a/1-exercises/B-array-some/exercise.js b/1-exercises/B-array-some/exercise.js
index fddc69ee..7f7ce60d 100644
--- a/1-exercises/B-array-some/exercise.js
+++ b/1-exercises/B-array-some/exercise.js
@@ -8,6 +8,15 @@
let pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]];
+//answer:
+function isNull(n) {
+ return n === null;
+}
+
+let containsNull = pairsByIndex.some(isNull);
+
+console.log(containsNull);
+
// 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);
diff --git a/1-exercises/C-array-every/exercise.js b/1-exercises/C-array-every/exercise.js
index 8980f463..f9ed962a 100644
--- a/1-exercises/C-array-every/exercise.js
+++ b/1-exercises/C-array-every/exercise.js
@@ -5,7 +5,7 @@
let students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"];
let group = ["Austine", "Dany", "Swathi", "Daniel"];
-let groupIsOnlyStudents = group.every(member => students); // complete this statement
+let groupIsOnlyStudents = group.every((member) => students); // complete this statement
if (groupIsOnlyStudents) {
console.log("The group contains only students");
diff --git a/1-exercises/D-array-filter/exercise.js b/1-exercises/D-array-filter/exercise.js
index 51837028..62375a2f 100644
--- a/1-exercises/D-array-filter/exercise.js
+++ b/1-exercises/D-array-filter/exercise.js
@@ -8,7 +8,9 @@
let pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"];
-let pairsByIndex; // Complete this statement
+let pairsByIndex = pairsByIndexRaw.filter(
+ (el) => Array.isArray(el) && el.length === 2
+); // Complete this statement
let students = ["Islam", "Lesley", "Harun", "Rukmini"];
let mentors = ["Daniel", "Irina", "Mozafar", "Luke"];
@@ -24,4 +26,4 @@ console.log(pairs);
/* EXPECTED RESULT
[ [ 'Islam', 'Luke' ], [ 'Lesley', 'Mozafar' ], [ 'Harun', 'Irina' ] ]
-*/
\ No newline at end of file
+*/
diff --git a/1-exercises/E-array-map/exercise.js b/1-exercises/E-array-map/exercise.js
index 5a157279..0fcce5e8 100644
--- a/1-exercises/E-array-map/exercise.js
+++ b/1-exercises/E-array-map/exercise.js
@@ -3,11 +3,11 @@
let numbers = [0.1, 0.2, 0.3, 0.4, 0.5];
-let numbersMultipliedByOneHundred; // complete this statement
+let numbersMultipliedByOneHundred = numbers.map((number) => number * 100); // complete this statement
console.log(numbersMultipliedByOneHundred);
/* EXPECTED RESULT
[10, 20, 30, 40, 50]
-*/
\ No newline at end of file
+*/
diff --git a/1-exercises/F-array-forEach/exercise.js b/1-exercises/F-array-forEach/exercise.js
index 985068cc..5237c7cb 100644
--- a/1-exercises/F-array-forEach/exercise.js
+++ b/1-exercises/F-array-forEach/exercise.js
@@ -9,6 +9,18 @@
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
+let newArr = arr.forEach((n) => {
+ if (n % 3 === 0 && n % 5 === 0) {
+ console.log("FizzBuzz");
+ } else if (n % 5 === 0) {
+ console.log("Buzz");
+ } else if (n % 3 === 0) {
+ console.log("Fizz");
+ } else {
+ console.log(n);
+ }
+});
+
/* EXPECTED OUTPUT */
/*
diff --git a/1-exercises/G-array-methods/exercise.js b/1-exercises/G-array-methods/exercise.js
index 4367ef6e..7555a9cb 100644
--- a/1-exercises/G-array-methods/exercise.js
+++ b/1-exercises/G-array-methods/exercise.js
@@ -4,7 +4,7 @@
*/
let numbers = [3, 2, 1];
-let sortedNumbers; // complete this statement
+let sortedNumbers = numbers.sort((a, b) => (a - b)); // complete this statement
/*
DO NOT EDIT BELOW THIS LINE
diff --git a/1-exercises/G-array-methods/exercise2.js b/1-exercises/G-array-methods/exercise2.js
index 4c68c3a6..fb100649 100644
--- a/1-exercises/G-array-methods/exercise2.js
+++ b/1-exercises/G-array-methods/exercise2.js
@@ -7,7 +7,7 @@
let mentors = ["Daniel", "Irina", "Rares"];
let students = ["Rukmini", "Abdul", "Austine", "Swathi"];
-let everyone; // complete this statement
+let everyone = mentors.concat(students); // complete this statement
/*
DO NOT EDIT BELOW THIS LINE
diff --git a/1-exercises/H-array-methods-2/exercise.js b/1-exercises/H-array-methods-2/exercise.js
index 59c5daa7..4717531c 100644
--- a/1-exercises/H-array-methods-2/exercise.js
+++ b/1-exercises/H-array-methods-2/exercise.js
@@ -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(everyone.length - 5); // complete this statement
/*
DO NOT EDIT BELOW THIS LINE
diff --git a/1-exercises/H-array-methods-2/exercise2.js b/1-exercises/H-array-methods-2/exercise2.js
index 14bb4318..475b39d6 100644
--- a/1-exercises/H-array-methods-2/exercise2.js
+++ b/1-exercises/H-array-methods-2/exercise2.js
@@ -7,7 +7,9 @@
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);
+}
/*
DO NOT EDIT BELOW THIS LINE
diff --git a/1-exercises/H-array-methods-2/exercise3.js b/1-exercises/H-array-methods-2/exercise3.js
index c8e079e4..7279417e 100644
--- a/1-exercises/H-array-methods-2/exercise3.js
+++ b/1-exercises/H-array-methods-2/exercise3.js
@@ -7,7 +7,7 @@
let ukNations = ["Scotland", "Wales", "England", "Northern Ireland"];
function isInUK(country) {
- return; // complete this statement
+ return ukNations.includes(country); // complete this statement
}
/*
diff --git a/1-exercises/I-string-replace/exercise.js b/1-exercises/I-string-replace/exercise.js
index 3f7104d7..a4fdd089 100644
--- a/1-exercises/I-string-replace/exercise.js
+++ b/1-exercises/I-string-replace/exercise.js
@@ -13,7 +13,11 @@
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/g, "cats")
+ .replace("day", "night")
+ .replace(10, 100000)
+ .replace("great day", "brilliant night");
/* EXPECTED OUTPUT */
diff --git a/1-exercises/J-string-substring/exercise.js b/1-exercises/J-string-substring/exercise.js
index 4624db68..14288304 100644
--- a/1-exercises/J-string-substring/exercise.js
+++ b/1-exercises/J-string-substring/exercise.js
@@ -6,7 +6,7 @@
let statement = "I like programming and dogs";
-statement = statement.substring();
+statement = statement.substring(0, 18);
console.log(statement);
diff --git a/1-exercises/J-string-substring/exercise2.js b/1-exercises/J-string-substring/exercise2.js
index a1d9bf62..cb541c6a 100644
--- a/1-exercises/J-string-substring/exercise2.js
+++ b/1-exercises/J-string-substring/exercise2.js
@@ -14,11 +14,11 @@ let names = [
"Arron Graham",
];
-names[0] = names[0].substring();
-names[1] = names[1].substring();
-names[2] = names[2].substring();
-names[3] = names[3].substring();
-names[4] = names[4].substring();
+names[0] = names[0].substring(0, 6);
+names[1] = names[1].substring(0, 7);
+names[2] = names[2].substring(0, 4);
+names[3] = names[3].substring(0, 4);
+names[4] = names[4].substring(0, 5);
names.forEach((name) => {
console.log(name);
diff --git a/1-exercises/J-string-substring/exercise3.js b/1-exercises/J-string-substring/exercise3.js
index 14f77417..525bfb21 100644
--- a/1-exercises/J-string-substring/exercise3.js
+++ b/1-exercises/J-string-substring/exercise3.js
@@ -8,7 +8,8 @@
let statement = "I do not like programming";
-let result = "";
+let result =
+ statement.substring(0, 4) + statement.substring(8, statement.length);
console.log(result);
From 248a1fdea42497608417f31fb233eb467c9c7843 Mon Sep 17 00:00:00 2001
From: ZahraaTayyar
Date: Tue, 21 Mar 2023 17:51:50 +0000
Subject: [PATCH 3/8] Mandatory-3 completed
---
2-mandatory/1-create-functions.js | 21 ++++++++++++++++-----
2-mandatory/2-oxygen-levels.js | 8 +++++++-
2-mandatory/3-bush-berries.js | 4 +++-
2-mandatory/test.js | 12 ++++++++++++
4 files changed, 38 insertions(+), 7 deletions(-)
create mode 100644 2-mandatory/test.js
diff --git a/2-mandatory/1-create-functions.js b/2-mandatory/1-create-functions.js
index 6df12961..34bf3368 100644
--- a/2-mandatory/1-create-functions.js
+++ b/2-mandatory/1-create-functions.js
@@ -3,7 +3,8 @@ 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(arr) {
+ return arr.slice(0, 5);
}
/*
@@ -11,7 +12,8 @@ Write a function that:
- Accepts an array as a parameter.
- Returns a new array containing the same elements, except sorted.
*/
-function sortArray() {
+function sortArray(arr) {
+ return arr.sort();
}
/*
@@ -24,7 +26,8 @@ Write a function that:
- Removes any forward slashes (/) in the strings.
- Makes the strings all lowercase.
*/
-function tidyUpString() {
+function tidyUpString(arr) {
+ return arr.map((str) => str.trim().replace("/", "").toLowerCase());
}
/*
@@ -33,7 +36,8 @@ Write a function that:
- Returns a new array containing the same elements, but without the element at the passed index.
*/
-function remove() {
+function remove(arr4, index) {
+ return arr4.replace(/index/g, "");
}
/*
@@ -44,7 +48,14 @@ Write a function that:
- Numbers greater 100 must be replaced with 100.
*/
-function formatPercentage() {
+function formatPercentage(arr) {
+ return arr.map((i) => {
+ if (i > 100) {
+ console.log("100%");
+ } else {
+ console.log(arr.map((str) => `${str.toFixed(2)}%`));
+ }
+ });
}
/* ======= TESTS - DO NOT MODIFY ===== */
diff --git a/2-mandatory/2-oxygen-levels.js b/2-mandatory/2-oxygen-levels.js
index 5711c5e5..d13a6bce 100644
--- a/2-mandatory/2-oxygen-levels.js
+++ b/2-mandatory/2-oxygen-levels.js
@@ -11,7 +11,13 @@
Some string methods that might help you here are .replace() and .substring().
*/
-function findSafeOxygenLevel() {}
+function findSafeOxygenLevel(planets, oxygenLvl) {
+ return planets.map((planet) => {
+ if (oxygenLvl >= 19.5 && oxygenLvl <= 23.5) {
+ return planets;
+ } else return undefined;
+ });
+}
/* ======= TESTS - DO NOT MODIFY ===== */
diff --git a/2-mandatory/3-bush-berries.js b/2-mandatory/3-bush-berries.js
index b434a507..d0c89c8f 100644
--- a/2-mandatory/3-bush-berries.js
+++ b/2-mandatory/3-bush-berries.js
@@ -22,7 +22,9 @@
*/
function isBushSafe(berryArray) {
- //Write your code here
+ if (berryArray.some((berry) => berry !== "pink")) {
+ return "Toxic! Leave bush alone!";
+ } else return "Bush is safe to eat from";
}
/* ======= TESTS - DO NOT MODIFY ===== */
diff --git a/2-mandatory/test.js b/2-mandatory/test.js
new file mode 100644
index 00000000..f0695fdf
--- /dev/null
+++ b/2-mandatory/test.js
@@ -0,0 +1,12 @@
+function isBushSafe(berryArray) {
+ if (berryArray.some((berry) => berry !== "pink")) {
+ return "Toxic! Leave bush alone!";
+ } else return "Bush is safe to eat from";
+}
+
+let b = ["pink", "pink", "pink", "neon", "pink", "transparent"];
+
+let d = ["pink", "pink"];
+
+console.log(isBushSafe(b));
+console.log(isBushSafe(d));
From 3191ffa708c50ed56c2212864cb77d2460afe340 Mon Sep 17 00:00:00 2001
From: ZahraaTayyar
Date: Tue, 21 Mar 2023 18:06:01 +0000
Subject: [PATCH 4/8] mandatory-4 completed
---
2-mandatory/4-space-colonies.js | 6 +++++-
2-mandatory/test.js | 11 -----------
2 files changed, 5 insertions(+), 12 deletions(-)
diff --git a/2-mandatory/4-space-colonies.js b/2-mandatory/4-space-colonies.js
index 30095213..f2c770df 100644
--- a/2-mandatory/4-space-colonies.js
+++ b/2-mandatory/4-space-colonies.js
@@ -15,7 +15,11 @@
*/
-function getSettlers() {}
+function getSettlers(families) {
+ return families.filter(
+ (family) => family[0] === "A" && family.includes("family")
+ );
+}
/* ======= TESTS - DO NOT MODIFY ===== */
diff --git a/2-mandatory/test.js b/2-mandatory/test.js
index f0695fdf..8b137891 100644
--- a/2-mandatory/test.js
+++ b/2-mandatory/test.js
@@ -1,12 +1 @@
-function isBushSafe(berryArray) {
- if (berryArray.some((berry) => berry !== "pink")) {
- return "Toxic! Leave bush alone!";
- } else return "Bush is safe to eat from";
-}
-let b = ["pink", "pink", "pink", "neon", "pink", "transparent"];
-
-let d = ["pink", "pink"];
-
-console.log(isBushSafe(b));
-console.log(isBushSafe(d));
From 565608cc3b05b0aac956cd2734cd4690d9cf44d3 Mon Sep 17 00:00:00 2001
From: ZahraaTayyar
Date: Tue, 21 Mar 2023 18:11:14 +0000
Subject: [PATCH 5/8] mandatory-5 completed
---
2-mandatory/5-eligible-students.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/2-mandatory/5-eligible-students.js b/2-mandatory/5-eligible-students.js
index f92478e0..c19622e4 100644
--- a/2-mandatory/5-eligible-students.js
+++ b/2-mandatory/5-eligible-students.js
@@ -7,7 +7,9 @@
- Returns an array containing only the names of the who have attended AT LEAST 8 classes
*/
-function getEligibleStudents() {}
+function getEligibleStudents(studentsAndAtt) {
+ return studentsAndAtt.filter((student) => student[1] >= 8);
+}
/* ======= TESTS - DO NOT MODIFY ===== */
From ab761706f7a2e7222e4b1e4f9c000ccb255c2ddb Mon Sep 17 00:00:00 2001
From: ZahraaTayyar
Date: Tue, 21 Mar 2023 18:31:35 +0000
Subject: [PATCH 6/8] mandatory-6 completed
---
2-mandatory/6-journey-planner.js | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/2-mandatory/6-journey-planner.js b/2-mandatory/6-journey-planner.js
index 25a14083..53c6ed5d 100644
--- a/2-mandatory/6-journey-planner.js
+++ b/2-mandatory/6-journey-planner.js
@@ -10,7 +10,7 @@
Now let's do this small exercise
Using string methods update the checkCodeIsThere() function
- - The function will have a string as a paramter
+ - The function will have a string as a parameter
- The function should check if the word "code" exists in the string
- If it does exist, return the index of it, if not return "Not found"
@@ -20,8 +20,8 @@
function checkCodeIsThere(stringText) {
let magicWord = "code";
//edit code below
- if (stringText) {
- return stringText;
+ if (stringText.includes(magicWord)) {
+ return stringText.indexOf(magicWord);
} else {
return "Not found";
}
@@ -64,7 +64,9 @@ function checkCodeIsThere(stringText) {
Hint: Use the corresponding array method to split the array.
*/
-function getTransportModes() {}
+function getTransportModes(arr) {
+ return arr.slice(1)
+}
/*
Implement the function isAccessibleByTransportMode that
@@ -81,7 +83,9 @@ function getTransportModes() {}
Hint: Use the corresponding array method to decide if an element is included in an array.
*/
-function isAccessibleByTransportMode() {}
+function isAccessibleByTransportMode(transportArr, TransportStr) {
+ return transportArr.includes(TransportStr)
+}
/*
Implement the function getLocationName that
@@ -92,7 +96,9 @@ function isAccessibleByTransportMode() {}
- Returns the name of the location
e.g: "Tower Bridge"
*/
-function getLocationName() {}
+function getLocationName(arr) {
+ return arr[0];
+}
/*
We arrived at the final method. it won't take long if you use the previously implemented functions wisely.
@@ -122,7 +128,9 @@ function getLocationName() {}
Advanced challange: try to use arrow function when invoking an array method.
*/
function journeyPlanner(locations, transportMode) {
- // Implement the function body
+ return locations
+ .filter((arr) => arr.includes(transportMode))
+ .map((arr) => arr[0]);
}
/* ======= TESTS - DO NOT MODIFY ===== */
From c2681cc5722267fd5ec30552826df2679705942c Mon Sep 17 00:00:00 2001
From: ZahraaTayyar
Date: Tue, 21 Mar 2023 18:34:07 +0000
Subject: [PATCH 7/8] mandatory-7 completed
---
2-mandatory/7-lane-names.js | 4 +++-
2-mandatory/test.js | 12 ++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/2-mandatory/7-lane-names.js b/2-mandatory/7-lane-names.js
index 40c31b68..b1037a6a 100644
--- a/2-mandatory/7-lane-names.js
+++ b/2-mandatory/7-lane-names.js
@@ -6,7 +6,9 @@
HINT: string and array methods that could be helpful (indexOf, filter)
*/
-function getLanes() {}
+function getLanes(streets) {
+ return streets.filter((street) => street.includes("Lane"));
+}
/* ======= TESTS - DO NOT MODIFY ===== */
diff --git a/2-mandatory/test.js b/2-mandatory/test.js
index 8b137891..a0415041 100644
--- a/2-mandatory/test.js
+++ b/2-mandatory/test.js
@@ -1 +1,13 @@
+function getLanes(streets) {
+ return streets.filter((street) => street.includes("Lane"));
+}
+const streetNames = [
+ "Abchurch Lane",
+ "Adam's Court",
+ "Addle Hill",
+ "Addle Lane",
+ "Alban Highwalk",
+];
+
+console.log(getLanes(streetNames));
From 7afd7fe794fe5512086c3f90afe13f13344d638a Mon Sep 17 00:00:00 2001
From: ZahraaTayyar
Date: Tue, 21 Mar 2023 18:43:58 +0000
Subject: [PATCH 8/8] mandatory-8 completed
---
2-mandatory/test.js | 13 -------------
1 file changed, 13 deletions(-)
delete mode 100644 2-mandatory/test.js
diff --git a/2-mandatory/test.js b/2-mandatory/test.js
deleted file mode 100644
index a0415041..00000000
--- a/2-mandatory/test.js
+++ /dev/null
@@ -1,13 +0,0 @@
-function getLanes(streets) {
- return streets.filter((street) => street.includes("Lane"));
-}
-
-const streetNames = [
- "Abchurch Lane",
- "Adam's Court",
- "Addle Hill",
- "Addle Lane",
- "Alban Highwalk",
-];
-
-console.log(getLanes(streetNames));