2022.05.17 TIL

E__ppo·2022년 5월 17일
0

cote

목록 보기
4/5
post-custom-banner

30. 최소직사각형

function solution(sizes) {
    let arr = [0,0]
    sizes.forEach(e=>{
        let [b,s] = e.sort((a,b)=>b-a)
        if(b>arr[0]) arr[0] =b
        if(s>arr[1]) arr[1] =s
    })
    return arr[0]*arr[1]
}

31. 같은 숫자는 싫어

function solution(arr)
{
    for(i=0; i<arr.length; i++){
       if(arr[i] === arr[i+1]){
            arr[i] = ""
       }
     }
        
    arr = arr.filter(i => i.length!=0)
        
        return arr
}

32. 두 개 뽑아서 더하기

function solution(numbers) {
    var answer = [];

    for(i=0; i<numbers.length; i++){
        for(j=i+1; j<numbers.length; j++){
            let sum = numbers[i]+numbers[j]
            if(!answer.includes(sum)){
                answer.push(sum)
            }
        }
    }
        answer = answer.sort((a,c) => a-c)
    
    return answer;
}

33. 로또의 순위

function solution(lottos, win_nums) {
    let answer = []
    let minLottos = (lottos.filter(it => win_nums.includes(it))).length
    let zeroCount=lottos.filter(item => item===0).length
    let rank=[6,6,5,4,3,2,1]
    answer.push(rank[minLottos+zeroCount])
    answer.push(rank[minLottos])
    

    return answer
}

33. 모의고사

function solution(answers) {
    let answer=[]
    let one = [1, 2, 3, 4, 5]
    let two = [2, 1, 2, 3, 2, 4, 2, 5]
    let three = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
    let correcCount=[0,0,0]
    let maxanswer=0;

    for(i=0; i<answers.length; i++){
        if(answers[i] === one[i%5])   { correcCount[0]++ }
        if(answers[i] === two[i%8])   { correcCount[1]++ }
        if(answers[i] === three[i%10]){ correcCount[2]++ }    
    }

    maxanswer = Math.max(...correcCount)

    for(i=0; i<3; i++)
        if(correcCount[i] === maxanswer) answer.push(i+1)
    

    return answer
}
post-custom-banner

0개의 댓글