프로그래밍
-
이벤트 루프?프로그래밍/Node 2021. 7. 4. 17:11
Node를 공부하면서, 중요한 개념인 이벤트 루프를 공부 해 보고자 한다. 내가 선택한 방법은 무식하지만 그냥 node doc문서를 다 해석하는 것. 1. 이벤트 루프는 무엇인가? 자바스크립트가 싱글 스레드임에도, Node가 non-blocking I/O 동작을 수행하도록 도와주는 프로그래밍 구조체 이다. 대부분의 최신 커널이 멀티 스레드이므로, 백그라운드에서 실행되는 여러 작업을 실행할 수 있다. 하나의 작업이 완료가 되면, 커널은 Node에게 알려준다. Node에게 알려 준 callback은 poll 큐에 추가 되고, 결국에는 실행 된다. 뒤에서 좀 더 자세하게 설명하겠다. 2. 이벤트 루프 설명 Node.js가 시작되면 이벤트 루프를 초기화하고 제공된 입력 스크립트를 처리 (또는이 문서에서 다루지 ..
-
객체로서의 함수와 기명 함수 표현식프로그래밍/Js 2021. 7. 2. 19:50
https://ko.javascript.info/function-object 를 보고 공부한 내용을 정리. 1. 객체로서의 함수 함수의 자료형은 객체이다. 그래서 함수를 호출할 수 있을 뿐 아니라 객체처럼 함수에 프로퍼티를 추가, 제거할 수 있다. 1. 'name' 프로퍼티 'name' 프로퍼티를 사용하면 함수이름을 가져올 수 있다. function sayHi() { alert("Hi"); } alert(sayHi.name); // sayHi 기본값을 사용해서 이름을 할당한 경우. function f(sayHi = function() {}) { alert(sayHi.name); // sayHi (이름이 있네요!) } f(); //(코드가 참 희한하게 생겼다) 객체 메서드 이름은 함수처럼 자동할당이 되지..
-
leetCode (Two Sum II - Input array is sorted) - Array, Binary Search프로그래밍/algorithm 2021. 7. 1. 10:57
문제 Given an array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Return the indices of the two numbers (1-indexed) as an integer array answer of size 2, where 1 { let left = 0; let right = numbers.length - 1; while (left < right) { let sum = numbers[left] + numbers[right]; if (sum === target) { return [left ..
-
leetCode (Pascal's Triangle) - Array, DP프로그래밍/algorithm 2021. 6. 28. 08:10
문제 Given an integer numRows, return the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: Example 1: Input: numRows = 5 Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]] 배경지식 1. Array - 메모리 상에 원소를 연속하게 배치한 자료구조 2. DP - 여러개의 하위 문제를 먼저 풀고, 그것을 쌓아올려 주어진 문제를 해결하는 알고리즘 문제해결 1.테이블 설계 DP[i][j]는 바로 위의 인접한 두 개의 숫자의 합니다 2.점화식 세우..
-
Node.js - 비동기 중심 모델프로그래밍/Node 2021. 6. 26. 15:16
비동기 중심 모델 싱글스레드 기반 Node를 처음 공부할 때, 맨 처음 들었던 Node의 2가지 속성이다. Node를 공부할 때마다 맨날 나오는 용어들이라서, 이제는 이 용어들을 듣는 것이 익숙했지만, 항상 마음속에는 두 가지의 질문 있었다. 1. 사용자들의 요청을 처리하는 쓰레드가 많으면 많을 수록 좋은 거 아닌감???? Node는 왜 Single-Thread기반인 거야??? 2. 도대체 비동기 중심이 뭐야??? 이러한, 궁금증들이 있었지만, 너무나도 게을렀던 나는 그것에 대한 답을 이제서야 찾아 보았다. Multi-Thread의 한계 Multi-Thread 방식은 서버의 요청 처리를 쓰레드에서 처리하도록 하여 병렬처리를 가능하도록 하는 방식이다. 쓰레드는 서버 CPU 자원을 시분할 형태로 나누어 가지..
-
leeCode (Maximum Subarray)-Array, Dp프로그래밍/algorithm 2021. 6. 26. 09:52
문제 Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. Example 2: Input: nums = [1] Output: 1 Example 3: Input: nums = [5,4,-1,7,8] Output: 23 배경지식 1. Array - 메모리 상에 원소를 연속하게 배치한 자료구조 특징 : 추가적으로 소모되는 메모리의 ..
-
leeCode (Search Insert Position) -Array프로그래밍/algorithm 2021. 6. 25. 08:40
문제 Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [1,3,5,6], target = 5 Output: 2 Example 2: Input: nums = [1,3,5,6], target = 2 Output: 1 Example 3: Input: nums = [1,3,5,6], target ..