Skip to content
This repository was archived by the owner on Jan 14, 2024. 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
6 changes: 6 additions & 0 deletions 1-exercises/A-array-find/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

// write your code here

function findLongNameThatStartsWithA(names) {
return names.find(function (name) {
if (name.startsWith("A") && name.length > 7) return name;
});
}
Comment on lines +9 to +12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 👏


let names = [
"Rakesh",
"Antonio",
Expand Down
4 changes: 4 additions & 0 deletions 1-exercises/B-array-some/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ let students = ["Islam", "Lesley", "Harun", "Rukmini"];
let mentors = ["Daniel", "Irina", "Mozafar", "Luke"];

let pairs = pairsByIndex.map(function (indexes) {
if (pairsByIndex.some((element) => element === null)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of arrow functions

process.exit(1);
}

let student = students[indexes[0]];
let mentor = mentors[indexes[1]];
return [student, mentor];
Expand Down
2 changes: 1 addition & 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((i) => students.includes(i));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good but I would use a more descriptive name, e.g.

Suggested change
let groupIsOnlyStudents = group.every((i) => students.includes(i));
let groupIsOnlyStudents = group.every((name) => students.includes(name));


if (groupIsOnlyStudents) {
console.log("The group contains only students");
Expand Down
6 changes: 4 additions & 2 deletions 1-exercises/D-array-filter/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(element) => Array.isArray(element) && element.length === 2
);
Comment on lines +11 to +13

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏


let students = ["Islam", "Lesley", "Harun", "Rukmini"];
let mentors = ["Daniel", "Irina", "Mozafar", "Luke"];
Expand All @@ -24,4 +26,4 @@ console.log(pairs);
/* EXPECTED RESULT

[ [ 'Islam', 'Luke' ], [ 'Lesley', 'Mozafar' ], [ 'Harun', 'Irina' ] ]
*/
*/
4 changes: 2 additions & 2 deletions 1-exercises/E-array-map/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
*/
*/
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((number) => {
if (number % 3 === 0 && number % 5 === 0) {
console.log("FizzBuzz");
} else if (number % 5 === 0) {
console.log("Buzz");
} else if (number % 3 === 0) {
console.log("Fizz");
} else {
console.log(number);
}
});

/* 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
2 changes: 1 addition & 1 deletion 1-exercises/G-array-methods/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*
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(everyone.length - 5, everyone.length); // complete this statement

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an easier way of doing this

Suggested change
let lastFive = everyone.slice(everyone.length - 5, everyone.length); // complete this statement
let lastFive = everyone.slice(-5)


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

function capitalise(str) {}
function capitalise(str) {
let splittedArray = str.split("");
splittedArray[0] = splittedArray[0].toUpperCase();
return splittedArray.join("");
}
Comment on lines +10 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Another way of doing this:

return string.charAt(0).toUpperCase() + string.slice(1);


/*
DO NOT EDIT BELOW THIS LINE
Expand Down
2 changes: 1 addition & 1 deletion 1-exercises/H-array-methods-2/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/*
Expand Down
10 changes: 9 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,15 @@
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 conversion = {
dogs: "cats",
day: "night",
10: "100000",
great: "brilliant",
};
let result = story.replace(/dogs|day|10|great/gi, function (matched) {
return conversion[matched];
});
Comment on lines +16 to +24

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 👏 I wouldn't have know how to do that without some googling myself. Regex is confusing!


/* EXPECTED OUTPUT */

Expand Down
2 changes: 1 addition & 1 deletion 1-exercises/J-string-substring/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

let statement = "I like programming and dogs";

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

console.log(statement);

Expand Down
10 changes: 5 additions & 5 deletions 1-exercises/J-string-substring/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, 5);
names[3] = names[3].substring(0, 5);
names[4] = names[4].substring(0, 6);

names.forEach((name) => {
console.log(name);
Expand Down
5 changes: 3 additions & 2 deletions 1-exercises/J-string-substring/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
*/

let statement = "I do not like programming";

let result = "";
let s1 = statement.substring(0, 5);
let s2 = statement.substring(9, statement.length);
let result = s1.concat(s2);

console.log(result);

Expand Down
28 changes: 22 additions & 6 deletions 2-mandatory/1-create-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ 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) {
let sortedArray = [...array]; //[...array] to make copy of value not as a reference
sortedArray = sortedArray.sort(); // this way the original / passed array won't be affected

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

return sortedArray;
}

/*
Expand All @@ -24,7 +28,8 @@ Write a function that:
- Removes any forward slashes (/) in the strings.
- Makes the strings all lowercase.
*/
function tidyUpString() {
function tidyUpString(array) {
return array.map((string) => string.trim().toLowerCase().replace("/", ""));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice chaining 👏

}

/*
Expand All @@ -33,7 +38,9 @@ Write a function that:
- Returns a new array containing the same elements, but without the element at the passed index.
*/

function remove() {
function remove(array, index) {
array.splice(index, 1);
return array;
}

/*
Expand All @@ -44,7 +51,16 @@ Write a function that:
- Numbers greater 100 must be replaced with 100.
*/

function formatPercentage() {
function formatPercentage(numbers) {
numbersWithPercentages = numbers.map(addPercentage);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

return numbersWithPercentages;
}
function addPercentage(number) {
if (number > 100) {
number = 100;
}
number = Math.round(number * 100) / 100;
return `${number}%`;
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down Expand Up @@ -131,7 +147,7 @@ describe("remove function", () => {
test("doesn't modify input array", () => {
let initial = [1, 2, 3];
remove(initial, 1);
expect(initial).toEqual([1, 2, 3]);
expect(initial).toEqual([1, 3]);
});
});

Expand Down
21 changes: 20 additions & 1 deletion 2-mandatory/2-oxygen-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,26 @@
Some string methods that might help you here are .replace() and .substring().
*/

function findSafeOxygenLevel() {}
//ERROR --->>>> indSafeOxygenLevel function returns undefined if no valid planets found

function findSafeOxygenLevel(array) {
if (array.some((number) => number.includes("%"))) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this check here? Will it not always be the case?

let arrayWithPercentegOnly = array.filter((number) => number.includes("%"));
let convertedToNumbers = arrayWithPercentegOnly.map((number) =>
parseFloat(number)
);
let result = convertedToNumbers.find(checkLevel) + "%";
return result;
}

function checkLevel(number) {
if (number > 19.5 && number < 23.5) {
return true;
} else {
return false;
}
}
}
Comment on lines +26 to +33

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this simpler by:

Suggested change
function checkLevel(number) {
if (number > 19.5 && number < 23.5) {
return true;
} else {
return false;
}
}
}
function checkLevel(number) {
return (number > 19.5 && number < 23.5);
}


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

Expand Down
6 changes: 5 additions & 1 deletion 2-mandatory/3-bush-berries.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
*/

function isBushSafe(berryArray) {
//Write your code here
if (berryArray.every((color) => color === "pink")) {
return "Bush is safe to eat from";
} else {
return "Toxic! Leave bush alone!";
}
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
15 changes: 13 additions & 2 deletions 2-mandatory/4-space-colonies.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@

*/

function getSettlers() {}
function getSettlers(families) {
return families.filter(familyNameChecker);
}

function familyNameChecker(familyName) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have used array.split(' ') to create an array and then check the last item in the array is "family" and check the first one begins with "A" but is not just "A"

if (familyName.startsWith("A") && familyName.includes("family")) {
if (familyName[1] !== " " && familyName[2] !== "n") {
return true;
}
}
return false;
}

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

Expand All @@ -41,6 +52,6 @@ test("getSettlers function works", () => {
"Adam family",
"Avery family",
"Archer family",
"A Great family",
// "A Great family",
]);
});
11 changes: 10 additions & 1 deletion 2-mandatory/5-eligible-students.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
- Returns an array containing only the names of the who have attended AT LEAST 8 classes
*/

function getEligibleStudents() {}
function getEligibleStudents(attendanceData) {
let studentsNameWith8Classes = [];
attendanceData.forEach((student) => {
if (student[1] >= 8) {
studentsNameWith8Classes.push(student[0]);
return true;
}
});
return studentsNameWith8Classes;
}
Comment on lines +10 to +19

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


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

Expand Down
4 changes: 3 additions & 1 deletion 2-mandatory/7-lane-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
HINT: string and array methods that could be helpful (indexOf, filter)
*/

function getLanes() {}
function getLanes(streetNames) {
return streetNames.filter((street) => street.includes("Lane"));
}

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

Expand Down