본문 바로가기

IT Note269

728x90
React #Rules of Hooks React Rules of Hooks Only call React Hooks in React Functions React Component Functions Custom Hooks Only call React Hoos at the Top Level Don't call them in nested functions Don't call them in any block statements + extra, unoffical Rule for useEffect(): ALWAYS add everything you refer to inside of useEffect() as a dependency useEffect(() => { setFormIsValid(email && password) }, [email]); // (.. 2022. 9. 24.
React #Understanding useReducer() useReducer() const [state, dispatchFn] = useReducer(reducerFn, initialState, initFn); state: The state snapshot used in the component re-render/ re-evaluation cycle dispatchFn: A function that can be used to dispatch a new action (i.e. trigger an update of the state) reducerFn: (prevState, action) => new State / A function that is triggered automatically once an action is dispatched (via dispatc.. 2022. 9. 24.
프로그래머스 #2021 KAKAO BLIND -신규 아이디 추천 lv1 문제 풀이 function solution(new_id) { let answer = ''; answer = getAvailableId(new_id); return answer; } function getAvailableId(id) { let recommandId = '' const idInValidRe = /[^-_.a-z0-9]/g; const doubleDotRe = /\.{2,}/g; const startDotRe = /^\./; const endDotRe = /\.$/; // 1단계 new_id의 모든 대문자를 대응되는 소문자로 치환합니다. recommandId = id.toLowerCase(); // 2단계 new_id에서 알파벳 소문자, 숫자, 빼기(-), 밑줄(_), 마침표(.)를 제외한 모.. 2022. 7. 4.
javascript #자바스크립트 객체와 SOLID 원칙 자바스크립트 객체와 SOLID 원칙 원시형 객체 리터럴 모듈 패턴 객체 프로토타입과 프로토타입 상속 new 객체 생성 클래스 상속 함수형 상속 멍키 패칭 1. 자바스크립트 원시형 (Primitive Type) JavaScript에서 원시 값(primitive, 또는 원시 자료형)이란 객체가 아니면서 메서드도 가지지 않는 데이터다. 원시 값에는 7종류, string, number (en-US), bigint (en-US), boolean, undefined, symbol, 그리고 null이 존재한다. 대부분의 경우, 원시 값은 언어 구현체의 가장 저급(low level) 단계에서 나타낸다. 모든 원시 값은 불변하여 변형할 수 없다. 원시 값 자체와, 원시값을 할당한 변수를 혼동하지 않는 것이 중요하다. .. 2022. 5. 29.
javascript #함수형 자바스크립트 프로그래밍 - 1~2장 기록 1장 함수형 자바스크립트 소개 함수형 프로그래밍 특징 page 6. 불변성 page 18. 객체지향 프로그래밍이 약속된 이름이 메서드를 대신 실행해 주는 식으로 외부 객체에게 위임을 한다면, 함수형 프로그래밍은 보조형 함수를 통해 완전히 위임해주는 방식을 취한다. 이는 더 높은 다형성과 안정성을 제공한다. page 20. findIndex 함수 예시 function findIndex(list, predicate) { for (let i = 0, i = list.length; i < len; i++) { if (predicate(list[i])) return i; } return -1; } 함수를 잘 다루기 위해 필수로 알아야 하는 기능들 고차 함수 함수를 인자로 받거나 함수를 리턴하는 함수 보통 고차 함.. 2021. 11. 29.
프로그래머스 #탐욕법(Greedy) - 구명보트 lv2 문제 풀이 function solution(people, limit) { let answer = 0; // 구명보트 수 let startIndex = 0; let endIndex = people.length - 1; let saveActivity = true; // 구출 작업 진행 여부 people.sort((a, b) => b - a); // 제일 무거운 사람 순으로 정렬 while (saveActivity) { // 마지막 한명을 태우고 구출 작업 종료 if(startIndex === endIndex) { answer++; startIndex++; saveActivity = false; break; } // 가장 가벼운 사람과 태웠을 때 제한 무게를 넘기지 않으면 2명을 태운다. if(people[s.. 2021. 9. 13.
프로그래머스 #탐욕법(Greedy) - 체육복 lv1 풀이 문제 function solution(n, lost, reserve) { let answer = 0; let result = []; // 여벌이 있는 학생이 도난당한 경우 lost 와 reserve 에서 제외합니다. let isNotReserve = reserve.filter((re) => lost.find((lo) => re === lo)); lost = lost.filter((re) => !isNotReserve.find((notReserve) => re === notReserve)); reserve = reserve.filter((re) => !isNotReserve.find((notReserve) => re === notReserve)); for (let i=1; i lo === i); if.. 2021. 9. 12.
프로그래머스 #정렬 - H-Index lv2 문제 풀이 function solution(citations) { var answer = 0; let sortCitations = citations.sort((a, b) => a - b); let len = sortCitations.length; for(let i=0; i c >= citation).length; if(citation >= cnt) { answer = len - i; break; } } return answer; } 채점결과 2021. 9. 12.
프로그래머스 #완전탐색 - 소수 찾기 lv2 문제 풀이 function solution(numbers) { let answer = 0; let allPermutations = []; // 모든 경우의 수 [순열] let permutationsSet = []; // 중복을 제거한 경우의 수 // 1. 숫자 조합 순열 구하기 allPermutations = getAllPermutations([...numbers]); // 2. 중복제거 permutationsSet = getPermutationsSet(allPermutations) // 3. 소수 갯수 구하기 answer = getCountDicimal([...new Set(permutationsSet)]); return answer; } // 1. 숫자 조합 순열 구하기 function getAllP.. 2021. 9. 12.
프로그래머스 #스택/큐 - 프린터 lv2 문제 풀이 function solution(priorities, location) { let answer = 0; let seq = location; let len = priorities.length; let result = priorities; let printList = []; let stop = true; while (stop) { if (printList.length === len) { stop = false; break; // 탐색 완료 } const targetPrint = result[0]; const remainPrints = result.slice(1); if(remainPrints.find((print) => print > targetPrint)) { // 뒤에 큰 숫자가 있으므로 인쇄.. 2021. 9. 10.
728x90
728x90