I know how to loop through an object and print out an array of values I want, but I'm having trouble figuring out printing it in the order that I want .
**The question is: **
Given a collection of game outcome records, determine who all the players are by returning an array of their names.
The array should be ordered by how the names are encountered.
Example Input:
[
{ winner: 'Alishah', loser: 'Bob', loser_points: 3 },
{ winner: 'Maria', loser: 'Xu Jin', loser_points: 1 },
{ winner: 'Elise', loser: 'Bob', loser_points: 2 },
{ winner: 'Elise', loser: 'Maria', loser_points: 4 },
{ winner: 'Alishah', loser: 'Maria', loser_points: 2 },
{ winner: 'Maria', loser: 'Xu Jin', loser_points: 3 },
{ winner: 'Xu Jin', loser: 'Elise', loser_points: 2 }
]
Expected Result:
['Alishah', 'Bob', 'Maria', 'Xu Jin', 'Elise']
**The code I have so far: **
let data = [
{ winner: 'Alishah', loser: 'Bob', loser_points: 3 },
{ winner: 'Maria', loser: 'Xu Jin', loser_points: 1 },
{ winner: 'Elise', loser: 'Bob', loser_points: 2 },
{ winner: 'Elise', loser: 'Maria', loser_points: 4 },
{ winner: 'Alishah', loser: 'Maria', loser_points: 2 },
{ winner: 'Maria', loser: 'Xu Jin', loser_points: 3 },
{ winner: 'Xu Jin', loser: 'Elise', loser_points: 2 }
];
console.log(main(data));