본문 바로가기

javascript27

542. 01 Matrix 542. 01 Matrix Medium Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Example 1: Input: mat = [[0,0,0],[0,1,0],[0,0,0]] Output: [[0,0,0],[0,1,0],[0,0,0]] Example 2: Input: mat = [[0,0,0],[0,1,0],[1,1,1]] Output: [[0,0,0],[0,1,0],[1,2,1]] Constraints: m == mat.length n == mat[i].length 1 2023. 2. 14.
1162. As Far from Land as Possible 1162. As Far from Land as Possible Medium Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or water exists in the grid, return -1. The distance used in this problem is the Manhattan distance: the distance between two cells (x0, y0).. 2023. 2. 10.
2306. Naming a Company 2306. Naming a Company Hard You are given an array of strings ideas that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows: Choose 2 distinct names from ideas, call them ideaA and ideaB. Swap the first letters of ideaA and ideaB with each other. If both of the new names are not found in the original ideas, then the name ideaA .. 2023. 2. 9.
904. Fruit Into Baskets 904. Fruit Into Baskets Medium You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array fruits where fruits[i] is the type of fruit the ith tree produces. You want to collect as much fruit as possible. However, the owner has some strict rules that you must follow: You only have two baskets, and each basket can only ho.. 2023. 2. 7.
1091. Shortest Path in Binary Matrix 1091. Shortest Path in Binary Matrix Medium Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1. A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to the bottom-right cell (i.e., (n - 1, n - 1)) such that: All the visited cells of the path are 0. All the adjacent cells of the path are 8-.. 2023. 2. 6.
2091. Removing Minimum and Maximum From Array 2091. Removing Minimum and Maximum From Array Medium You are given a 0-indexed array of distinct integers nums. There is an element in nums that has the lowest value and an element that has the highest value. We call them the minimum and maximum respectively. Your goal is to remove both these elements from the array. A deletion is defined as either removing an element from the front of the array.. 2023. 2. 1.
모던 자바스크립트 Deep Dive - 프로미스 콜백 함수 콜백 함수는 ES6이전에 비동기 처를 위해 사용하던 하나의 패턴이지만, 다음과 같은 단점들이 있어 ES6에서 프로미스 패턴이 도입된다. 1. 콜백 헬로 인해 가독성이 나쁘다. 비동기 처리 결과를 가지고 또다시 비동기 함수를 호출하여 콜백 함수 호출이 중첩되어 복잡도가 높아지는 현상 let g = 0 setTimeout(() => {g = 100;},0) console.log(g) // 0 위의 코드에서 처럼 비동기 처리 결과를 변수에 할당하려고 하면 기대한 대로 동작하지 않는다. setTimeout은 실행후 브라우저에서 타이머가 만료되면 콜백 함수를 태스크 큐로 이동한다, 그리고 콜 스택이 비어 있으면, 이때 태스크 큐에서 콜스택으로 이동하고 콜백함수가 실행된다. 그렇기 때문에 g = 100 .. 2022. 12. 31.
모던 자바스크립트 Deep Dive - REST API REST REST란 HTTP를 기반으로 클라이언트가 서버의 리소스에 접근하는 방식을 규정한 아키텍쳐이다. - REST의 기본원칙을 성실히 치킨 서비스 디자인을 RESTful이라고 표현한다. - REST API는 REST를 기반으로 서비스 API를 구현한 것을 의미한다. REST API 구성 - 자원 : URL - 행위 : HTTP 요청 메서드 - 표현 : 페이로드 REST API 설계 원칙 1. URL는 리소스를 표현해야 한다. 리소스를 식별할 수 있는 이름은 동사보다는 명사를 사용한다. # bad GET /getTodos/1 # good GET /Todos/1 2. 리소스에 대한 행위는 HTTP 요청 메서드로 표현한다. 요청 메서드는 크게 5가지가 있다. (GET, POST, PUT, PATCH, DE.. 2022. 12. 31.
모던 자바스크립트 Deep Dive - Ajax Ajax란? Ajax란 자바스크립트를 사용하여 브라우저가 서버에게 비동기 방식으로 데이터를 요청하고, 서버가 응답한 데이터를 수신하여 웹페이지를 동적으로 갱신하는 프로그래밍 방식을 말합니다. Ajax가 나오기 이전의 웹페이지는 html 태그로 시작해서 html 태그로 끝나는 완전한 HTML을 서버로부터 전송받아 웹페이지 전체를 처음부터 다시 렌더링 하는 방식으로 동작했습니다. 그렇기 떄문에 다음과 같은 문제점들이 있었습니다. 1. 변경할 필요가 없는 부분까지 포함된 완전한 HTML을 서버로부터 매번 다시 전송받기 때문에 불필요한 데이터 통신이 발생한다. 2. 매번 새로운 HTML을 전송 받기 때문에 깜빡이는 현상이 발생한다. 3. 클라이언트와 서버와의 통신이 동기 방식으로 동작하기 때문에 서버로 부터 응.. 2022. 12. 31.