์•Œ๊ณ ๋ฆฌ์ฆ˜(js)

33. ๋ชจ์˜๊ณ ์‚ฌ

tnqlscho 95 2022. 11. 16. 23:37

๐Ÿ˜‡  ๋ฌธ์ œ

 

๐Ÿ™  ๋‹ต

function solution(answers) {
    var answer = [];
    let supoja1 = [1,2,3,4,5]
    let supoja2 = [2,1,2,3,2,4,2,5]
    let supoja3 = [3,3,1,1,2,2,4,4,5,5]
    let count = []
    
    let one = answers.filter((v,i)=>v==supoja1[i%supoja1.length]).length;
    let two = answers.filter((v,i)=>v==supoja2[i%supoja2.length]).length;
    let thr = answers.filter((v,i)=>v==supoja3[i%supoja3.length]).length;
    count.push(one,two,thr);
    
    for(let i=0; i<count.length; i++){
        if(Math.max(...count)==count[i]) answer.push(i+1)
    }

    return answer;
    
}
answers.filter((v,i)=>v==supoja1[i%supoja1.length]).length;

์ €๊ธฐ์„œ i%supoja1.length ์ด ๋ถ€๋ถ„์ด ์ดํ•ด๊ฐ€ ์ž˜ ์•ˆ๋˜์—ˆ๋‹ค..ใ… 

์ง„์งœ ์ˆ˜ํฌ์ž๋Š” ๋‚˜์ธ๊ฐ€๋ดใ… ใ… ใ