TIL 2024-05-28

박요셉·2024년 5월 28일

TIL

목록 보기
29/60

오전

  1. 개인 과제 리펙토링
    RTK를 쓰는 방식에 맞게 코드 수정, 컴포넌트 분리, 날짜별 정렬 등등 코드 리펙토링

오후

  1. 프로그래머스 문제 풀이
  • 두 개 뽑아서 더하기
  • 콜라 문제
const exchangeCoke = (needCoke, exchangeCoke, myEmptyCoke) => {
    const exchangedCoke = Math.floor(myEmptyCoke / needCoke) * exchangeCoke;
    const leftoverCoke = myEmptyCoke % needCoke + exchangedCoke;
    return [exchangedCoke, leftoverCoke];
}

function solution(a, b, n) {
    let answer = 0;
    let currentEmptyCoke = n;

    while (currentEmptyCoke >= a) {
        const [exchangedCoke, leftoverCoke] = exchangeCoke(a, b, currentEmptyCoke);
        answer += exchangedCoke;
        currentEmptyCoke = leftoverCoke;
    }

    return answer;
}
  • 명예의 전당
function solution(k, score) {
    let answer = []
    let honor = []
    score.forEach((item,idx) => {
        honor.push(item)
        idx < k -1 ? answer.push(honor.sort((a,b) => b - a)[idx]) : answer.push(honor.sort((a,b) => b - a)[k-1])
        
    })
    console.log(answer)
    return answer
}
  • 카드 뭉치
function solution(cards1, cards2, goal) {
    for (const item of goal) {
        if (cards1.includes(item)) {
            if (cards1[0] === item) {
                cards1.shift();
            } else {
                return 'No';
            }
        } else if (cards2.includes(item)) {
            if (cards2[0] === item) {
                cards2.shift();
            } else {
                return 'No';
            }
        } else {
            return 'No';
        }
    }
    return 'Yes';
}

저녁

  1. Immer.js 학습 예정
  1. 컴포넌트는 어떻게 분리해야되는가?
    블로그에 정리했음
profile
개발자 지망생

0개의 댓글