Conversation
| } | ||
| } | ||
|
|
||
| var locationsByBoat = londonLocations.filter(transport).map(transport); |
There was a problem hiding this comment.
Try to make sure the function you use with filter always returns a boolean value. Yours will return a string or undefined which happen to work as true and false respectively with Javascript but it isn't very clean. For example you could write this as
var locationsByBoat = londonLocations.filter(location => location.includes("river boat")).map(location => location[0]);
so the logic for the two parts is separate. However in a real application we wouldn't mix different data (like the location name and the types of transport) as this example does.
| } | ||
| var eligibleStudentNames = attendances | ||
| .filter(namesOfEligibleStudents) | ||
| .map(namesOfEligibleStudents); // TODO: Complete this line. |
There was a problem hiding this comment.
Same thing here. This kind of works "by accident" because Javascript thinks "" is false and other strings are true but you shouldn't write code that relies on this. Write a predicate function (e.g. called isEligible) that return true or false, and do the map separately. Or you can do it inline again:
var eligibleStudentNames = attendances.filter(student => student[1] >= 8).map(student => student[0])
| return someNames.find(isLongAndStartsWithA); | ||
| } | ||
| function isLongAndStartsWithA(name) { | ||
| return name.startsWith("A") && name.length > 7; |
There was a problem hiding this comment.
Good. This is always the kind of function you should be using with find or filter.
| } | ||
|
|
||
| function isInArrayStudents(name) { | ||
| return students.includes(name); |
| console.log(num); | ||
| } | ||
| } | ||
|
|
No description provided.