function doesOwnSet(player, type) {
// we'll use "chaining" here, so every next method will be called upon
// what previous method have returned
// `return` statement will return the result of the very last method
// first, lets take an array of `position` object keys
// which are "position1", "position2" and so on
return Object.keys(positions)
// then, create an array of positions object
// this will return Array
.map(function (key) {
return positions[key];
})
// then, pick up only positions with specified type (aka set)
// this will return Array
.filter(function (pos) {
return pos.type === type;
})
// finally, check if specified player owns every position of the set
// this will return Boolean
.every(function (pos) {
return pos.owner === player;
});
}
I don't understand where the words "key" and "pos" come from. Are these the names of the functions? I really don't get it despite the comments. It was an answer to this question. The code works, but I just don't understand what it does.