I have a an array of objects and want to find the player with the highest score which also does not exceed a certain score (for example 20 points). How do I do so?
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
}