본문 바로가기

Javascript25

[JavaScript] class, 클로저, Prototype을 통한 객체지향 실질적인 데이터를 가지고 있는 필드와 그 필드에 접근하기 위한 메서드를 묶을 때 객체를 사용한다.이런 경우 자바스크립트에서는 흔히 class를 사용한다.하지만 class 말고 다른 방법으로 구현할 수도 있는데 각 방법을 비교해 보았다. 1. classclass Animator { private currentValue: number = 0; private isAnimating = false; forward() { this.isAnimating = true; this.currentValue += 1; } stop() { this.isAnimating = false; } getValue() { return this.currentValue; }} 특징: this를 통해 모든 .. 2025. 9. 4.
[JavaScript] 실행 컨텍스트 https://youtu.be/EWfujNzSUmw?si=Ik297-UzEH90eSmO위의 강의 정리한 내용 실행 컨텍스트는 각 스코프별로 코드가 실행되는 환경 정보를 담고 있는 객체이다. 코드 실행을 위해 존재한다. 0. 실행 컨텍스트는 언제 생성하고 언제 없어지는가- 코드 실행시키면 콜 스택에 실행 컨텍스트를 담는다.- 글로벌 실행 컨텍스트 위에 함수A의 실행 컨텍스트가 올라가고... 이런식. 가장 위에 있는 실행 컨텍스트만 활성화됨.- 일단 실행되면 사라진다.- 마지막 라인까지 코드가 모두 실행되면 글로벌 실행 컨텍스트도 사라진다. 1. Record로 호이스팅 이해console.log(name);var name = "doringri";- var로 정의한 변수 선언문 이전에 해당 변수의 값을 찍었을 .. 2025. 7. 17.
[JavaScript] 그래프 알고리즘 인접한 노드를 탐색하는 자료구조로, DFS를 이용하여 탐색한다. BFS로도 구현할 수 있지만 내가 DFS가 익숙하기에...function dfs(graph, visited, node) { if (visited[node]) return; visited[node] = true; console.log("Visiting:", node); for (let neighbor of graph[node]) { dfs(graph, visited, neighbor); }}// 예시const graph = { 0: [1, 2], 1: [0, 3], 2: [0, 4], 3: [1], 4: [2]};const visited = Array(Object.keys(graph).length).fill(false).. 2025. 5. 9.
[JavaScript/알고리즘] CountDiv 오랜만에 다시 하는 코딜리티...A와 B 사이에 K로 나눴을 때 몫이 0이 되는 수가 몇 개인지 세는 문제입니다. https://app.codility.com/demo/results/trainingGDW5F8-WJ7/ Test results - CodilityWrite a function: function solution(A, B, K); that, given three integers A, B and K, returns the number of integers within the range [A..B] that are divisible by K, i.e.: { i : A ≤ i ≤ B, i mod K = 0 } For example, for A = 6, B = 11 and K = 2, your fapp.. 2025. 3. 1.
[JavaScript/React] 다른 탭 간에 데이터 공유하기(postMessage) 프로젝트 중 다른 탭 간의 데이터를 공유하는 기능이 필요했다. window.postMessage 혹은 BroadcastChannel.postMessage를 통해 데이터를 공유할 수 있다.window.postMessage는 다른 도메인 간에도 전송이 가능하고(보안을 위해 origin을 설정하는 것이 좋다), 특정 탭에만 전송이 가능하다. 아래와 같은 코드이다.const subWindow = window.open("/test", "_blank");subWindow.postMessage("hello", "*"); BroadcastChannel.postMessage는 channel을 구독하고 있으면 다수의 탭에도 메시지 전송이 가능하고, 같은 도메인에서만 전송이 가능하다. 아래는 BroadcastChannel... 2025. 2. 9.
[JavaScript/알고리즘] 체육복 (Greedy) 프로그래머스 Lv 1 - 체육복 Solved-Algorithm/JavaScript/프로그래머스/1/42862. 체육복 at main · ParkBible/Solved-AlgorithmThis is an auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - ParkBible/Solved-Algorithmgithub.com 좀 많이 헤맸습니다. 이게 1레벨이라니...근데 작성된 코드를 보면 별거 없음... (그리디 특징인가?)function solution(n, lost, reserve) { const losts = lost.filter(l .. 2025. 1. 11.
[JavaScript/알고리즘] 게임 맵 최단거리 (BFS) 프로그래머스 Lv 2 - 게임 맵 최단거리 Solved-Algorithm/JavaScript/프로그래머스/2/1844. 게임 맵 최단거리 at main · ParkBible/Solved-AlgorithmThis is an auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - ParkBible/Solved-Algorithmgithub.com 상하좌우로 움직일 수 있는 전형적인 BFS 문제입니다.function solution(maps) { const n = maps.length; const m = maps[0].length; co.. 2025. 1. 10.
[JavaScript/알고리즘] PermCheck Lesson 4 (Counting Elements) - PermCheck(Easy) Test results - CodilityA non-empty array A consisting of N integers is given. A permutation is a sequence containing each element from 1 to N once, and only once. For example, array A such that: A[0] = 4 A[1] = 1 A[2] = 3 A[3] = 2 is a permutation, but array A such that: A[0] =app.codility.com배열의 값들이 연속적인 값이면 1을, 그렇지 않다면 0을 출력하는 문제입니다. 시도1 (실패)funct.. 2025. 1. 8.
[JavaScript/알고리즘] PassingCars (누적값 문제) Lesson 5 (Prefix Sums) - PassingCars(Easy) Test results - CodilityA non-empty array A consisting of N integers is given. The consecutive elements of array A represent consecutive cars on a road. Array A contains only 0s and/or 1s: 0 represents a car traveling east, 1 represents a car traveling west. The goal is to countapp.codility.com점수: 40/100 도로와 차들이 있다. 차는 값이 0일때 동쪽, 1일때 서쪽으로 움직인다.위의 그림처럼 A[.. 2025. 1. 8.
[JavaScript/알고리즘] FrogRiverOne Lesson 4 (Counting Elements) - FrogRiverOne(Easy) Test results - CodilityA small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0) and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river. You are given an arrayapp.codility.com 부끄러운 이야기지만 제 블로그니까 해봅니다.처음에 영어로 된 문제 이해 못해서 18점 받았습니다.. 2025. 1. 7.
[JavaScript/알고리즘] TapeEquilibrium (feat. 경계값 테스트) Lesson 3 (Time Complexity) - TapeEquilibrium(Easy) Test results - CodilityA non-empty array A consisting of N integers is given. Array A represents numbers on a tape. Any integer P, such that 0 app.codility.com점수: 84/100 배열을 두 부분으로 나눠서 각 부분의 합계를 구한 뒤 차이를 구하고, 그 차이의 최솟값을 구하는 문제입니다. 예를 들어서 [3, 1, 2, 4, 3] 이라는 배열이 있다면 3+1+2 / 4+3 으로 나눴을 때의 차이가 1로 가장 작기 때문에 답은 1입니다. 초기 코드function solution(A) { le.. 2025. 1. 5.
[JavaScript/알고리즘] PermMissingElem Lesson 3 (Time Complexity) - PermMissingElem(Easy) Test results - CodilityAn array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing. Your goal is to find that missing element. Write a function: function solution(A); that, given aapp.codility.com점수: 100/100 1부터 n까지의 수가 존재하는 배열(순서 무작위) 에서 빠진 수 하나를 .. 2025. 1. 5.
[JavaScript/알고리즘] FrogJmp Lesson 3 (Time Complexity) - FrogJmp(Easy) Test results - CodilityA small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D. Count the minimal number of jumps that the smalapp.codility.com X의 위치에 있는 개구리가 Y와 같거나 먼 위치로 이동하려고 하는데 한번에 D만큼만 이동할 수 있습니다. .. 2025. 1. 5.
[JavaScript/알고리즘] CyclicRotation (feat. 테스트 케이스) Lesson 2 (Arrays) - CyuclicRotation(Easy) Test results - CodilityAn array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9,app.codility.com점수: 62/100 일단 코딜리티는 문제를 제출하면 코드 수정을 못하더군요.테스트 케이스를 추가하는 능력도 중.. 2025. 1. 4.
[JavaScript/알고리즘] BinaryGap 먼저 아래는 Codility의 데모 문제들을 풀어볼 수 있는 사이트입니다.  Developer Training | Test Coding Skills Online - CodilityFind longest sequence of zeros in binary representation of an integer.app.codility.com 사이트의 첫 번째 문제, BinaryGap (Easy) 입니다.Easy라고는 하는데 영문으로 된 문제는 처음 풀어봐서 좀 어지럽습니다. https://app.codility.com/demo/results/trainingFQ7EBE-YTU/ Test results - CodilityA binary gap within a positive integer N is any maxima.. 2025. 1. 3.