본문 바로가기
javascript find How to properly use Javascript Find 자바스크립트 find 로 배열에서 요소 찾기 Find find() 메서드는 주어진 판별 함수를 만족하는 첫 번째 요소의 값을 반환한다. js Find example const array1 = [5, 12, 8, 130, 44] const found = array1.find(element => element > 10) console.log(found) // expected output: 12 속성 중 하나를 사용하여 배열에서 객체 찾기 const inventory = [ { name: "apples", quantity: 2 }, { name: "bananas", quantity: 0 }, { name: "cherries", quantity: .. 2020. 9. 21.
Javascript Some, Every How to properly use Javascript Some 자바스크립트 Some, Every 사용하기 Some some() 메서드는 배열 안의 어떤 요소라도 주어진 판별 함수를 통과하는지 테스트한다. js Some example const array = [1, 2, 3, 4, 5] // checks whether an element is even const even = element => element % 2 === 0 console.log(array.some(even)) // expected output: true 배열의 요소 테스트, 하나라도 10보다 큰지 판별 function isBiggerThan10(element, index, array) { return element > 10 } ;[2,.. 2020. 9. 21.
detect iPhone X device with JavaScript 자바스크립트로 아이폰X 디바이스 감지하는 방법 IPhoneX Resolution 아이폰X 해상도 IPhone X : 1125 X 2436 IPhone XS : 828 X 1792 IPhone XMAX : 1242 X 2688 const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream const ratio = window.devicePixelRatio || 1 const screen = { width: window.screen.width * ratio, height: window.screen.height * ratio, } const iosX = screen.width == 1125 && screen.height === 2436.. 2020. 9. 21.
commit messages Patterns for writing better git commit messages 더 나은 git 커밋 메시지를 작성하기 위한 패턴 Types asdasdasd feat : A new feature 새로운 기능 개발 fix : A bug fix 버그 수정 refactor : refactoring production code 코드 리팩토링 chore : Build process, no production code change 패키지 or 빌드 프로세스 또는 보조 도구 변경 pakage.json, .gitignore docs : Documentation only changes 문서 만 변경 README.md perf : A code change that improves performance 성능을 향상 .. 2020. 9. 21.
React useCallback 사용하기 useCallback const memoizedCallback = useCallback(() => { doSomething(a, b) }, [a, b]) 메모이제이션된 함수를 재사용 useCallback example import React, { useCallback } from "react" export default function MyParent({ term }) { const handleClick = useCallback( item => { console.log("You clicked ", item) }, [term] ) return } // Recreate increment on every change of delta! const increment = useCallback(() => setC(c.. 2020. 9. 21.
React useMemo 사용하기 // a, b가 바뀔때만 리렌더링 const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]) 메모이제이션된 값을 재사용 의존성 값 [a, b] 가 변경 되었을때 재계산하여 렌더링 시 고비용 계산을 방지 배열이 없을 경우 렌더링 때마다 새 값 계산 메모이제이션(memoization) 컴퓨터 프로그램이 동일한 계산을 반복해야 할 때, 이전에 계산한 값을 메모리에 저장함으로써 동일한 계산의 반복 수행을 제거하여 프로그램 실행 속도를 빠르게 하는 기술 useMemo example import React, { useMemo } from "react" const users = [ { id: "a", name: "Robin" }, { id: "b.. 2020. 9. 21.