-
-
Notifications
You must be signed in to change notification settings - Fork 261
London10-Afsha-Hossain-JS1-Week4 #236
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 |
---|---|---|
|
@@ -3,8 +3,11 @@ | |
Using .find(), we'd like to find the first name which starts with A and is longer than 7 letters. | ||
*/ | ||
|
||
// we are using function with a parameter that is an array of string | ||
|
||
// write your code here | ||
|
||
|
||
let names = [ | ||
"Rakesh", | ||
"Antonio", | ||
|
@@ -17,9 +20,46 @@ let names = [ | |
"Ahmed", | ||
]; | ||
|
||
function isLongName(singleName) { | ||
return singleName.length > 7; | ||
} | ||
|
||
let longName = names.find(isLongName); | ||
|
||
function isStartingWithA(singleName) { | ||
return singleName[0] === "A"; | ||
} | ||
|
||
let nameStartingWithA = names.find(isStartingWithA); | ||
|
||
function findLongNameThatStartsWithA(names) { | ||
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 To write the code simpler, on line 40 we can do the comparison directly as there is just one line of code.
|
||
return nameStartingWithA && longName; | ||
|
||
} | ||
|
||
let longNameThatStartsWithA = findLongNameThatStartsWithA(names); | ||
|
||
|
||
console.log(longNameThatStartsWithA); | ||
|
||
/* EXPECTED OUTPUT */ | ||
// "Alexandra" | ||
|
||
|
||
// function findLongName(names) { | ||
// let longName = []; | ||
// if (names.length > 7) { | ||
// longName.push(names); | ||
// } | ||
// return longName; | ||
// } | ||
|
||
// function findLongNameThatStartsWithA(string){ | ||
// let LongNameStartingWithA = []; | ||
// for (let letter of string) { | ||
// if (findLongName(string) && letter[0] === "A") { | ||
// LongNameStartingWithA.push(string) | ||
// } | ||
// } | ||
// return LongNameStartingWithA | ||
// } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,11 @@ | |
let students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; | ||
let group = ["Austine", "Dany", "Swathi", "Daniel"]; | ||
|
||
let groupIsOnlyStudents; // complete this statement | ||
let groupIsOnlyStudents = group.every(isOnlyStudent); // complete this statement | ||
|
||
function isOnlyStudent(list) { | ||
return list.includes(students); | ||
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. Good use of every. What is the value of |
||
} | ||
|
||
if (groupIsOnlyStudents) { | ||
console.log("The group contains only students"); | ||
|
@@ -16,3 +20,4 @@ if (groupIsOnlyStudents) { | |
/* EXPECTED RESULT */ | ||
|
||
// The group does not contain only students | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,9 @@ | |
let mentors = ["Daniel", "Irina", "Rares"]; | ||
let students = ["Rukmini", "Abdul", "Austine", "Swathi"]; | ||
|
||
let everyone; // complete this statement | ||
|
||
let everyone = mentors.concat(students); // complete this statement | ||
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. Good use of
|
||
// let everyone = [...mentors, ...students]; // alternate solution | ||
|
||
/* | ||
DO NOT EDIT BELOW THIS LINE | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ | |
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("dogs", "cats").replace("great", "brilliant").replace("day", "night"); | ||
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. Good use of replace, FYI there is a way to replace all the occurrence with one
|
||
|
||
/* EXPECTED OUTPUT */ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(arrayOfItems) { | ||
return arrayOfItems.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(arrayOfItems) { | ||
return Array.from(arrayOfItems).sort(); | ||
} | ||
|
||
/* | ||
|
@@ -24,7 +26,11 @@ Write a function that: | |
- Removes any forward slashes (/) in the strings. | ||
- Makes the strings all lowercase. | ||
*/ | ||
function tidyUpString() { | ||
function tidyUpString(arrayOfStrings) { | ||
for (const singleString of arrayOfStrings) { | ||
console.log(singleString.trim()); | ||
} | ||
return singleString.trim().replace("/","").toLowerCase(); | ||
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 |
||
} | ||
|
||
/* | ||
|
@@ -45,6 +51,7 @@ Write a function that: | |
*/ | ||
|
||
function formatPercentage() { | ||
|
||
} | ||
|
||
/* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,14 @@ | |
- Returns an array containing only the names of the who have attended AT LEAST 8 classes | ||
*/ | ||
|
||
function getEligibleStudents() {} | ||
function findName(studentArray) { | ||
let filterArray = studentArray.filter((element) => {(element[1] >= 8) { | ||
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. It seems the |
||
return element[0]; | ||
} | ||
}); | ||
// let modifyArray = filterArray.map(element => element[0]) | ||
// return modifyArray | ||
} | ||
|
||
/* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,15 @@ | |
HINT: string and array methods that could be helpful (indexOf, filter) | ||
*/ | ||
|
||
function getLanes() {} | ||
let laneNames = []; | ||
|
||
|
||
function getLanes(roadNames) { | ||
if (roadNames.includes("Lane")) { | ||
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. As the hint said, indexOf would be useful to help check the partial match in the string. |
||
laneNames.push(roadNames); | ||
} | ||
return laneNames; | ||
} | ||
|
||
/* ======= 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.
Good use of
find
function. FYI it is also possible to write line 23-27 into one statement. The benefit is that you can save the effort on thinking a function nameisLongName
. It is a personal coding style, not a rule to follow though.