전체 승률에서 N의 조건을 제외하고 구해야 정확한 답을 구할 수 있음
function solution(weights, head2head) {
var answer = [];
let obj = {
};
weights.forEach((weight,index)=>{
obj[index] = [0,0,weight,index+1];
});
for(let i = 0; i < weights.length ; i++){
let round = 0;
for(let j = 0; j < weights.length ; j++){
if(i !== j ){
if( head2head[i][j] === 'W' ){
obj[i][0]++;
if( weights[i] < weights[j] ) {
obj[i][1]++;
}
}
if(head2head[i][j] !== 'N'){
round++;
}
}
}
if(round != 0){
obj[i][0] = obj[i][0] / round;
}
else {
}
}
console.log(Object.values(obj))
let arr = Object.values(obj);
arr.sort((a,b)=>{
if(a[0]!==b[0]){
return b[0]-a[0];
}
else {
if(a[1]!==b[1]){
return b[1]-a[1];
}
else {
if(a[2]!==b[2]){
return b[2]-a[2];
}
else {
if(a[3]!==b[3]){
return a[3]-b[3];
}
}
}
}
});
//console.log(arr)
return arr.map((e)=>{
return e[3];
});
}