Skip to content

Week 3 exercises & practises#53

Open
havvarslan wants to merge 5 commits intorarmatei:masterfrom
havvarslan:week-3
Open

Week 3 exercises & practises#53
havvarslan wants to merge 5 commits intorarmatei:masterfrom
havvarslan:week-3

Conversation

@havvarslan
Copy link

No description provided.

Copy link
Collaborator

@tekul tekul left a comment

Choose a reason for hiding this comment

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

Great work Havva 💯 . Just be careful when writing predicate functions for use with filter, find and so on. Make sure they always return true or false for each possible value passed in.

}
}

var locationsByBoat = londonLocations.filter(transport).map(transport);
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good. This is always the kind of function you should be using with find or filter.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you Luke

}

function isInArrayStudents(name) {
return students.includes(name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

console.log(num);
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good 👍 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants