I'm struggling to filter out duplicate player names from an array of objects and create a new array with only unique player names in the same order. I have considered using a forEach loop or a similar approach, but I am unsure of how to handle 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;
};
For example:
const playerNames = [
{ winner: 'Sam', loser: 'Bruce', loser_points: 10 },
{ winner: 'Sam', loser: 'Hakim', loser_points: 9 }]
Expected Output: [Sam, Bruce, Hakim]