Добрый день.
Подскажите, пожалуйста, вот в этом коде из задания 13:
var gameRules = {
diceNumber: 2,
maxAttempts: 3
};
var firstCat = {
name: ‘Кекс’,
points: 0
};
var secondCat = {
name: ‘Рудольф’,
points: 0
};
var cats = [firstCat, secondCat];
var runGame = function (rules, players) {
for (var currentAttempt = 1; currentAttempt <= rules.maxAttempts; currentAttempt++) {
for (var i = 0; i < players.length; i++) {
var throwResult = keks.throwDice(rules.diceNumber, rules.diceNumber * 6);
players[i].points += throwResult;
console.log(players[i].name + ’ выбросил ’ + players[i].points);
}
}
return players;
};
var getWinners = function (players) {
var winners = [];
var max = players[0];
for (var i = 0; i < players.length; i++) {
var currentPlayer = players[i];
if (currentPlayer.points > max.points) {
max = currentPlayer;
console.log('Новый рекордсмен: ’ + currentPlayer.points);
}
}
return winners;
};
cats = runGame(gameRules, cats);
console.log(cats);
var tops = getWinners(cats);
console.log(tops);
В условии внутри цикла внутри функции getWinners мы сравниваем “currentPlayer.points > max.points”.
Почему ниже мы пишем
max = currentPlayer, а не
max.points = currentPlayer.points?
Спасибо.