-
자바스크립트, 동기 vs 비동기 (Synchronous vs Asynchronous)Frontend 2021. 8. 8. 22:55
싱글 스레드(Single Thread) 언어 자바스크립트는 싱글 스레드 언어라고 불린다. 여기서 스레드(Thread)는 프로세스 내에서 실행되는 흐름을 최소 단위를 말한다. 그리고 스레드는 자신만의 프로그램 카운터와 시스템 레지스터, 그리고 스택을 가진다. 프로그램 카운터는 다음에 실행될 명령어를 계속 추적하는 역할을 하고, 레지스터는 CPU가 요청을 처리하는 데 필요한 데이터를 일시적으로 가지고 있는 기억 장치이며 스택은 함수 호출 시에 전달되는 인자나 실행 종료 후 되돌아갈 주소 값, 함수 내의 변수 등을 저장하는 메모리 공간이다. 스레드는 프로세스에 할당된 메모리나 자원들을 공유하며, 각각의 스레드가 독립적으로 작업을 수행하기 위해 각자의 레지스터, 스택을 가진다. 스레드는 라이트웨이트 프로세스라고..
-
[LeetCode] Array101 - Find All Numbers Disappeared in an ArrayAlgorithm 2021. 5. 29. 22:59
Find All Numbers Disappeared in an Array Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Example 1: Input: nums = [4,3,2,7,8,2,3,1] Output: [5,6] Example 2: Example 2: Input: nums = [1,1] Output: [2] Constraints: n == nums.length 1 [1, , , 4, ] - 그리고 숫자가 들어있는 칸만 남겨둔다 => [1, 4] 이렇게 풀면 총 3번 ..
-
[LeetCode] Array101 - Third Maximum NumberAlgorithm 2021. 5. 23. 15:09
Third Maximum Number Given integer array nums, return the third maximum number in this array. If the third maximum does not exist, return the maximum number. Example 1: Input: nums = [3,2,1] Output: 1 Explanation: The third maximum is 1. Example 2: Example 2: Input: nums = [1,2] Output: 2 Explanation: The third maximum does not exist, so the maximum (2) is returned instead. Example 3: Example 3:..
-
[LeetCode] Arrays101 - Valid Mountain ArrayAlgorithm 2021. 5. 16. 19:40
Valid Mountain Array Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if: arr.length >= 3 There exists some i with 0 arr[i + 1] > ... > arr[arr.length - 1] Example 1: Input: arr = [2,1] Output: false Example 2: Input: arr = [..
-
[LeetCode] Arrays101 - Remove Duplicates from Sorted ArrayAlgorithm 2021. 5. 9. 15:57
Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Clarification: Confused why the returned value is an integer but your answer is an array? Note that the input..
-
[LeetCode] Arrays101 - Remove ElementAlgorithm 2021. 5. 9. 14:51
Remove Element Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you leave beyond the new length. Clarification: Confused why the returned value is an in..
-
[LeetCode] Arrays101 - Merge Sorted ArrayAlgorithm 2021. 5. 8. 23:58
Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has a size equal to m + n such that it has enough space to hold additional elements from nums2. Example 1: Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,..
-
[LeetCode] Arrays101 - Squares of a Sorted ArrayAlgorithm 2021. 5. 8. 23:38
아주 오랜만에 다시 시작한 알고리즘 문제 풀기! (그동안 노션으로 휘리릭~ 간단하게 정리하는 것에 맛들려서 블로그에 손을 안댔는데 매우 반성하고 있다. 하하...) Squares of a Sorted Array Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1: Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, i..
-
JavaScript, 숫자 타입이 아닌 값을 숫자로 바꾸는 다양한 방법 - feat. Number()/parseInt/Unary plus(+)/Unary negation(-)Frontend 2020. 11. 8. 18:51
JavaScript에서 숫자 타입이 아닌 값을 숫자로 바꿀 때는 주로 Number나 parseInt를 사용한다. Number When used as a function, Number(value) converts a string or other value to the Number type. If the value can't be converted, it returns NaN. Number는 함수로 사용 시 string이나 다른 값들을 Number type으로 변환해준다. 만약에 값을 변환할 수 없을 때는 NaN을 리턴한다. parseInt The parseInt() function parses a string argument and returns an integer of the specified radix..
-
알아두면 유용한 TypeScript의 Utility type 정리Frontend 2020. 6. 21. 22:11
TypeScript의 Utility Type 업무할 때 종종 튀어 나오는 애들인데 내가 잘 모르는 것 같아서 한 번 쭉 정리해보았다. 정리하다보니 진작 알아뒀으면 유용하게 많이 썼을텐데 싶은 것들이 엄청 많다. 심심할 때마다 다시 읽어봐야겠다. Partial 주어진 Type의 모든 property를 optional로 세팅한 Type을 구성한다. 다시 말해 주어진 Type의 모든 부분 집합 type을 return한다. 즉, 아래 Todo interface에 title과 description이 정의되어 있는데, Todo 중에서 일부 속성으로만 이루어진 type을 지정하고 싶을 때, Partial을 사용하면 된다. interface Todo { title: string; description: string; ..