I'm trying to iterate over an array of objects, and in a new array, return only the players, their names in the same order and not listed more than once.. Was thinking I could do something similar to this or with a forEach loop but I'm not really sure how to tackle the multiple occurrences
const players = function(outcomes) {
const arr = [];
for (let i = 0; i < outcomes.length; i++) {
if (outcomes.includes(winner, loser))
arr.push(arr[i]);
}
return arr;
};
Example Input and Expected Output:
const playerNames = [
{ winner: 'Sam', loser: 'Bruce', loser_points: 10 },
{ winner: 'Sam', loser: 'Hakim', loser_points: 9 }]
Output I want: [Sam, Bruce, Hakim]