19주차 알고리즘

이동규·2023년 9월 26일

코테

목록 보기
10/22

const  solution = (s1=[],s2=[])=>{
    return s1.filter((e)=>s2.includes(e)).length
}

function solution(common=[]) {
   
    let d =  common[1] - common[0]=== common[2] - common[1] ? true:false;
    console.log(d);
    if (d === true) {
        return common[0] + common.length -1 * (common[1]- common[0]);
    }
    else{
        return common[0] * Math.pow(common[1]/common[0],common.length);
    }
        
}

function solution(numlist, n) {
    let result = []
    result = numlist.sort((a, b) => {
        const [numA, numB] = [Math.abs(a - n), Math.abs(b - n)];
        if(numA === numB){
            return b - a;
        }
        return numA - numB;
    })
    return result;
}

마지막 문제는 못품 중요 포인트 구조분해와 sort함수를 결합하여 활용하는 것이 key point이다.

0개의 댓글