작성
·
233
0
4중 for문이 이해가 안가 이런식으로 만들어봤는데 혹시 가능한가요?
<html>
<head>
<meta charset="UTF-8">
<title>출력결과</title>
</head>
<body>
<script>
function solution(test){
let mathScore = {};
let possible = false;
let answer=0;
test.map((t)=>{
t.map((t2,index)=>{
mathScore[t2] = mathScore[t2]? [...mathScore[t2],index+1]:[index+1]
})
})
for(let i =1; i<test.length+1; i++){
for(let j=1; j<test.length+1; j++){
if(i!==j){
for(let k=0; k<test.length; k++){
if(mathScore[i][k] < mathScore[j][k]){
possible= true;
}
}
}
}
possible?answer++:null
possible = false;
}
return answer;
}
let arr=[[3, 4, 1, 2], [4, 3, 2, 1], [3, 1, 4, 2]];
console.log(solution(arr));
</script>
</body>
</html>