-
-
Notifications
You must be signed in to change notification settings - Fork 261
London Class 10 - Andrius Isin - JS1 - Week 4 #232
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,13 @@ 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]; | ||
if (indexes !== null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your condition works fine, so well done for that! but the aim of this exercise is using some() method on pairsByIndex array. Could you think of using some() instead of line 19. |
||
let student = students[indexes[0]]; | ||
let mentor = mentors[indexes[1]]; | ||
return [student, mentor]; | ||
} else { | ||
process.exit([1]); | ||
} | ||
}); | ||
|
||
console.log(pairs); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,15 @@ | |
*/ | ||
|
||
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; | ||
|
||
let newArray = arr.forEach((number) => { | ||
if (number % 3 === 0) { | ||
console.log("Fizz"); | ||
} else if (number % 5 === 0) { | ||
console.log("Buzz"); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please read the instruction again, Andrius. There are 3 conditions. You have successfully done first and second condetions but could you add the last condition as well and print "FizzBuzz" when needed. |
||
console.log(number); | ||
} | ||
}); | ||
/* EXPECTED OUTPUT */ | ||
|
||
/* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,11 @@ | |
Tip: use the string method .split() and the array method .join() | ||
*/ | ||
|
||
function capitalise(str) {} | ||
function capitalise(str) { | ||
let arr = str.split(""); | ||
arr[0] = arr[0].toUpperCase(); | ||
return arr.join(""); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice one indeed! |
||
/* | ||
DO NOT EDIT BELOW THIS LINE | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,12 @@ | |
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/g, "night") | ||
.replace(/great/g, "brilliant") | ||
.replace(/10/g, "100000"); | ||
console.log(result); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any specific reason that you used regular expression? |
||
|
||
/* EXPECTED OUTPUT */ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,34 @@ | |
Write a function that: | ||
- Accepts an array as a parameter. | ||
- Returns a new array containing the first five elements of the passed array. | ||
npm test -- --testPathPattern 1-create-functions.js | ||
*/ | ||
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.slice().sort(); | ||
} | ||
|
||
/* | ||
NOTE: This exercise is the same as one you did last week - try to do it again using things you learnt this week. | ||
Think about what is better about this solution than your one last week, and what is worse. | ||
NOTE: This exercise is the same as one you did last week - try to do it again using things | ||
you learnt this week. Think about what is better about this solution than your one last | ||
week, and what is worse. | ||
|
||
Write a function that: | ||
- Takes an array of strings as input. | ||
- Removes any spaces in the beginning or end each string. | ||
- Removes any forward slashes (/) in the strings. | ||
- Makes the strings all lowercase. | ||
*/ | ||
function tidyUpString() { | ||
function tidyUpString(array) { | ||
return array.map((string) => string.trim().replace("/", "").toLowerCase()); | ||
} | ||
|
||
/* | ||
|
@@ -33,7 +38,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(array, index) { | ||
return array.filter((element, i) => i !== index); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could pass your tests but it isn't very efficient. Imagine if you have a lenghthy array, looping through isn't efficient here. I recommend using methods like slice and concat |
||
} | ||
|
||
/* | ||
|
@@ -44,7 +50,13 @@ Write a function that: | |
- Numbers greater 100 must be replaced with 100. | ||
*/ | ||
|
||
function formatPercentage() { | ||
function formatPercentage(numbers) { | ||
return numbers.map((number) => { | ||
if (number > 100) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The instruction is saying if number >= 100 then return "100%". Please amend your if statement |
||
number = 100; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bit isn't right. Can you think why? You are looping through array of numbers and then reassigning 100 to each element in return. |
||
} | ||
return `${Math.round(number * 100) / 100}%`; | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function doesn't pass the test and returns undefined. |
||
} | ||
|
||
/* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,12 @@ | |
*/ | ||
|
||
function isBushSafe(berryArray) { | ||
//Write your code here | ||
let safeToEat = berryArray.every((color) => color === "pink"); | ||
if (safeToEat) { | ||
return "Bush is safe to eat from"; | ||
} else { | ||
return "Toxic! Leave bush alone!"; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice one! |
||
} | ||
|
||
/* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,11 @@ | |
|
||
*/ | ||
|
||
function getSettlers() {} | ||
function getSettlers(voyagers) { | ||
return voyagers.filter( | ||
(family) => family.startsWith("A") && family.includes("family") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again startsWith is really handy here, but there's another simple way to get the first index of word and see if it is equal to "A" |
||
); | ||
} | ||
|
||
/* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,11 @@ | |
- Returns an array containing only the names of the who have attended AT LEAST 8 classes | ||
*/ | ||
|
||
function getEligibleStudents() {} | ||
function getEligibleStudents(students) { | ||
return students | ||
.filter((student) => student[1] >= 8) | ||
.map((student) => student[0]); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well done for using filter and map |
||
/* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(array) { | ||
return array.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(modes, transportMode) { | ||
return modes.includes(transportMode); | ||
} | ||
|
||
/* | ||
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(locationAndTransports) { | ||
return locationAndTransports[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((location) => location.includes(transportMode)) | ||
.map((location) => location[0]); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine Andrius, you have already defined a funcition above called getLocationName, can you think how you can use this function in line 133? |
||
|
||
/* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the "startsWith" method you used. Nice! but can you think of another way of checking the second condition without using any method?