개체 배열을 가지며 특정 점수 (예 : 20 점)를 초과하지 않는 가장 높은 점수를 가진 플레이어를 찾고 싶습니다. 어떻게해야합니까?특정 값을 초과하지 않는 개체 배열에서 가장 높은 값을 찾습니다. - 자바 스크립트
는let playerScores = [
{ player: 'Dealer',
score: 19,
cards: 'A of ♥, 5 of ♦' },
{ player: 'Player1',
score: 18,
cards: '10 of ♦, 8 of ♦' },
{ player: 'Player2',
score: 23,
cards: '6 of ♦, 6 of ♥, J of ♠' }
]
console.log(playerScores)
// iterates through playerScores
for (let i in playerScores) {
if (playerScores[i].score > 20) {
console.log(playerScores[i].player + ' BUSTED!')
// removes the object with a score over 21 from the array
playerScores.splice(i,1)
}
return playerScores
}
코드를 어떻게 작동하지 않습니다 작동? –
점수가 가장 높은 플레이어를 찾아야합니다.이 경우 딜러는 점수가 19 점입니다. – Evelina
예! 20보다 낮은 점수를 얻은 플레이어를 찾고 싶습니다. – Evelina