본문 바로가기

다채로운 이야기

(74)
1207. Unique Number of Occurrences (Javascript) Hi... I have another array problem.The level is easy, but it is hard for me.However, I won't give up; I'll do my best. Anyway, to summarize this problem, I just need to check the unique count.So, I used the Map object and Set. Here is my answer. First, I convert the array to a Map, where the Map is [key, value], so I add the count as the value.Then, I initialize the Set because a Set can check f..
3005. Count Elements With Maximum Frequency (javascript) Summarize : just counting the Maximun Frequency so I use a Map to keep track of the countsi store the elements in an Array as keys, and their counts as values.Here is my code, and it feels too long, so I'm not satisfied with it.so i ask to Gpt for refactoring.and here is the answer. the code by gpt looks better than mine...and I learned something new, such as the nullish coalescing operator.It r..
리액트 forwardRef 좀..정리 forwardRef란?-> 상위 컴포넌트에서 전달받은 Ref를 하위 컴포넌트로 전달하는 역할 -> 의문 : 리액트에서는 원래 부모에서 자식으로 props를 넘겨주는데 굳이 Ref까지 사용을 해야하나? 라는 생각이 들음그래서 찾아봄 props는 데이터 전달에 사용:props는 컴포넌트에 데이터를 전달하기 위한 수단. 자식 컴포넌트는 전달받은 props를 이용해서 UI를 렌더링하거나 동작을 결정함. 컴포넌트의 로직이나 상태에 영향을 주고, 주로 데이터나 함수 전달에 사용됨ref는 DOM 요소나 컴포넌트 인스턴스에 직접 접근할 때 사용:ref는 주로 자식 컴포넌트의 DOM 요소나 컴포넌트 인스턴스에 직접 접근하기 위해 사용됨.props로는 DOM이나 특정 요소에 대한 직접적인 접근 권한을 줄 수 없기 때문에,..
내가 보기 위해 정리한 자바스크립트 methods(splice, split, slice...) indexOf: 호출한 string객체에서 주어진 값과 일치하는 첫 번째 인덱스를 반환. 단,첫 번째 등장 인덱스를 찾을 수 없으면 -1. 또한 대소문자를 구분함indexOf(찾는 값, 위치)인데 찾는 값의 위치가 변수인 위치보다 더 작으면, 즉 위치를 더 크게 잡으면 이 또한 -1을 반환함자매품으로 lastIndexOf()도 있음. 이건 같은 문자가 있을 때, 가장 늦게 나온 값의 위치는 반환함 indexOf를 사용해서 문자열 내의 특정 문자 숫자 세기예) var str = "To be, or not to be, that is the question.";var count = 0;var pos = str.indexOf("e"); //pos는 4의 값을 가집니다. while (pos !== -1) {  c..
392. Is Subsequence (Javascript) Hi, I solved the Leetcode problem 392.It's about comparing two strings.s should be a subsequence of t, and we have to consider the order,but the characters in s can appear separately within t.To summarize, it's just about checking if s is a subsequence.Please read the description. Why is the first example 'true'?It's because s is a subsequence of t,even if the characters are not contiguous.Howev..
React Hooks정리 및 쫌쫌따리 constructor: 컴포넌트를 새로 만들 때마다 호출되는 클래스 생성자 메서드컴포넌트가 업데이트 되는 상황 :props가 변경될때State가 변경될때 -> setState 부모 컴포넌트가 리렌더링 될 때This.forceUpdate로 강제로 렌더링을 트리거할 때라이프사이클 메서드render() -> 라이프 사이클 메서드 중, 유일하게 필수 메서드  React hook정리useState  ->  형태 : const [a, setA] = useState(type) 상태관리 -> 기본적으로 상태관리할 때 사용하는 훅, 근데 렌더링이 느려서 값이 마음대로 바로바로 업데이트가 안됨 useEffect -> 형태 useEffect(() => {}, [파라미터]) -> 파라미터에 useState의 상태를 넣어서 사..
React createPortal정리 리액트로 pj를 할 때, 음.. css적으로 좀 꼬일 때가 있긴 했었다. 그럴때면 그냥 막?노동식으로 css를 하나하나 다 고쳐줬고, 될 때까지 수정을 했는데.. 이런 기능이 있었네..ㅎ...처음에는 포탈이 뭐여라면서 머리로부터 받아드리기 싫어했.. 새로운 거 배울 때마다.. 머리가 좀 거부하는 느낌이랄까..그럴때마다 나를 다그치며 이건 순전히 내 뇌의 장난이야. 운동과 같이 뇌에서도 근육이 키워지려고 힘들어하는 것뿐이야라며 나를 다그친다.. 각설하고 공부한 내용 정리해보자. portal을 사용하는 이유 : css 스타일 충돌을 피하기 위해 dom트리 밖으로 모달을 분리함.-> 즉, 돔 트리 구조와 독립적인 위치에서 컴포넌트를 렌더링할 수 있게 해주는 역할 의문점 : 굳이 왜.. 다른 곳에서 렌더링을 해..
58. Length of Last Word (Javascript) Hi. it's been a while.These days, I've started studying JS again.I solved a JS algorithm problem.This problem is part of the Top 150 Interview Questions,so I have to solve it. anyway, I think it is about Array problem.I first converted the String to an array and then used a for loop and an if statement. We need to save time, so I count backwards like this.   so my submission is~~!!   I'm not sur..