아무 생각 없이 품
function solution(players, callings) {
var answer = [];
for (let i = 0; i < callings.length; i++) {
const index = players.indexOf(callings[i]);
const player = players[index - 1]
players[index-1] = callings[i]
players[index] = player
}
answer.push(...players)
return answer;
}
function solution(players, callings) {
let answer = []
const hash = new Map()
players.map((player,index)=>{hash.set( player, index)})
for(let call in callings) {
const winnerIndex = hash.get(callings[call]);
const winner = players[winnerIndex]
const player = players[winnerIndex-1]
players[winnerIndex] = player
players[winnerIndex-1] = winner
hash.set(winner, winnerIndex-1).set(player,winnerIndex)
}
const temp =new Map([...hash.entries()].sort((a, b) => a[1] - b[1]))
answer = [...temp.keys()]
return answer
}