all is well!!

32. ๋กœ๋˜์˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„ ๋ณธ๋ฌธ

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

32. ๋กœ๋˜์˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„

tnqlscho 95 2022. 11. 15. 23:39

๐Ÿ˜‡  ๋ฌธ์ œ

 

๐Ÿ™  ๋‹ต

function solution(lottos, win_nums) {
    var count = [];
    var answer = [];
    let min=0;
    let zero=0;
    
    for(let i=0; i<lottos.length; i++){
        for(let j=0; j<lottos.length; j++){
            if(lottos[i]==win_nums[j]) min++;
        }
        if(lottos[i]==0) zero++;
    }
    
    count=[min+zero,min]
    
    for(let i=0; i<count.length; i++){
        if(count[i]==6) answer.push(1);
        else if(count[i]==5) answer.push(2);
        else if(count[i]==4) answer.push(3);
        else if(count[i]==3) answer.push(4);
        else if(count[i]==2) answer.push(5);
        else if(count[i]<=1) answer.push(6);
    }
    
    return answer;
}
// 1. 0์ด ์•„๋‹Œ ์ˆซ์ž๋“ค์ด ๋‹น์ฒจ๋ฒˆํ˜ธ์™€ ๋งž๋Š”์ง€ ๋น„๊ตํ•ด์„œ ๊ฐฏ์ˆ˜ ์ถœ๋ ฅ
// 2. ์ตœ๊ณ ์—๋Š” 0์— ์ „๋ถ€ ๋‹น์ฒจ๋ฒˆํ˜ธ๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ณ  ๊ฐฏ์ˆ˜์— ๋”ํ•˜๊ธฐ
// 3. ์ตœ์ €์—๋Š” 0์— ์ „๋ถ€ ๋‹น์ฒจ๋ฒˆํ˜ธ๊ฐ€ ์—†๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ณ  ๊ฐฏ์ˆ˜์— ๋”ํ•˜๋Š”๊ฒƒ ์—†์Œ
// 4. ์กฐ๊ฑด๋ฌธ์œผ๋กœ ๊ฐฏ์ˆ˜๋ฅผ ๋น„๊ตํ•ด์„œ ์ตœ์ €๋“ฑ์ˆ˜ ์ตœ๊ณ ๋“ฑ์ˆ˜ ๊ฐ€๋ ค๋‚ด๊ธฐ

 

 

Comments