전체 글 247

Typescript for React

npx create-react-app 내 앱 이름 --template typescript npm i --save-dev @유형/styled-components npm i styled-components // index에서 root에러가 난다면 const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement) //이렇게 수정 interface : object shape(객체모양)을 TypeScript에게 설명해주는 개념 interface PlayerShape { name: string age: number } const sayHello = (playerObj: PlayerShape) => `Hello ${playerObj.nam..

Typescript (Basic & Functions)

쓰는 이유 1. Type 안정성 // js는 [1,2,3] + false === '1,2,3false' function divide(a,b){ return a/b } divide('xxx') === NaN // 인자가 2개가 들어오지도 않았고 타입도 안맞지만 에러를 안띄움 2. 런타임에러(코드실행중의 에러) 방지 const obj = {name:'manseon'} obj.hi() // obj.hi is no a function에러가 뜸 // 즉, 실행을 이미 시키고 에러를 띄움 // 애초에 obj에 hi가 없음을 먼저 인지하는 편이 좋음 문법 타입을 지정안해줘도 추론함 let a = 'a' a = 'b' // ok let a = 'a' a = 1 //type 에러 남 구체적 명시 let b : boole..

Styled Components

tag에 style 직접 먹일 때 일반적 사용법 : 이름을 붙여 줄 수 있다 const BoxOne = styled.div` background-color: teal; width: 100px; height: 100px; ` props내리기 가능 const Box = styled.div` background-color: ${props => props.bgColor}; width: 100px; height: 100px; ` 컴포넌트 extend하기 const Box = styled.div` background-color: ${props => props.bgColor}; width: 100px; height: 100px; ` const Circle = styled(Box)` border-radius: 50px..

Tree

//! 1진트리 class Tree { //tree의 constructor를 생성 : tree의 자식 노드들을 엘리먼트로 담을 children 배열로 선언 constructor(value) { this.value = value this.children = [] } // 자식 노드 생성 메소드 구현 : new 키워드로 자식 노드를 생성 한 후, children 배열에 push insertNode(value) { const childNode = new Tree(value) this.children.push(childNode) } // tree에서 value값을 탐색하기 위한 메소드 구현 contains(value) { // 현재 노드의 value 값이 찾는 값과 일치한다면 true 반환 if (this.va..

순열, 중복순열, 조합, 중복조합

순열 function solution(arr, n) { let result = [] function DFS(n, tempArr) { if (n === 0) return result.push(tempArr) for (let i = 0; i < arr.length; i++) { if (!tempArr.includes(arr[i])) DFS(n - 1, tempArr.concat(arr[i])); } } DFS(n, []) return result } // n만 주어졌을 때 function solution(n) { let result = [] let N = n function DFS(n, tempArr) { if (n === 0) return result.push(tempArr) for (let i = 1; i

목표 금액이 될 수 있는 경우의 수 찾기

친구가 이런식으로 만들어 달라고 요청했다 중복조합으로 구했다 let input = `[231A01] 100 [231A02] 200 [231A03] 300 [231A04] 400 [231A05] 500 [231A06] 600 [231A07] 700` let price = `800 5000 10000 11000` function solution1(input, price) { let inputArr = trans(input) let priceArr = price.split('\n').map(ele => parseInt(ele.trim())) priceArr.forEach(price => { let result = [] function repeat(sum, tempArr, index) { if (sum === ..