목록분류 전체보기 (83)
kohigowild

input 안에 텍스트를 입력하고 submit 하면 하단에 리스트가 추가되는 형식 title 우측 괄호 안에는 리스트 개수 출력 import { useState } from "react"; function App() { const [toDo, setToDo] = useState(""); const [toDos, setToDos] = useState([]); const onChange = (event) => setToDo(event.target.value); const onSubmit = (event) => { event.preventDefault(); if (toDo === "") { return; } setToDo(""); setToDos((currentArray) => [toDo, ...current..

Apply Operations to an Array You are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith element of nums: If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation. After performing all t..

Minimum Difference Between Highest and Lowest of K Scores You are given a 0-indexed integer array nums, where nums[i] represents the score of the ith student. You are also given an integer k. Pick the scores of any k students from the array so that the difference between the highest and the lowest of the k scores is minimized. Return the minimum possible difference. Example 1: Input: nums = [90]..

Best Time to Buy and Sell Stock You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. Example 1: Input: prices = ..

💡 DOM (Document Object Model) XML이나 HTML 문서에 접근하기 위한 인터페이스, 문서 내의 모든 요소를 정의하고 각각의 요소에 접근하는 방법을 제공 자바스크립트에서 HTML을 접근하기 위해 DOM 사용 🛰️ DOM 브라우저의 렌더링 엔진은 텍스트 파일로 생성된 웹 문서를 브라우저 화면에 보이도록 하기 위해서 이 웹 문서를 브라우저가 이해할 수 있는 구조로 구성하여 메모리에 올리는데 이를 DOM이라 한다. DOM은 웹 문서를 하나의 객체로 정의하고, 웹 문서를 이루는 텍스트나 이미지, 표 등 모든 요소도 각각 객체로 정의한다. => 문서 전체는 document 객체, 이미지는 image 객체, 이미지 속성(Attribute)인 alt, src는 image 객체의 속성(Proper..

두 개 뽑아서 더하기 문제 설명 정수 배열 numbers가 주어집니다. numbers에서 서로 다른 인덱스에 있는 두 개의 수를 뽑아 더해서 만들 수 있는 모든 수를 배열에 오름차순으로 담아 return 하도록 solution 함수를 완성해주세요. 제한사항 numbers의 길이는 2 이상 100 이하입니다. numbers의 모든 수는 0 이상 100 이하입니다. 나의 답안 function solution(numbers) { let arr = []; for (let i = 0; i < numbers.length; i++) { for (let j = 0; j < numbers.length; j++) { if (i !== j) arr.push(numbers[i] + numbers[j]); } } arr.sor..

🚩 useState() 리액트 컴포넌트에서 동적인 값을 상태(state)라고 부른다. 사용자 인터랙션을 통해 컴포넌트의 상태값이 동적으로 바뀔 경우에는 상태를 관리하는 것이 필요하다. Hooks 기능이 도입된 리액트 16.8 버전부터 useState() 함수를 통해 함수형 컴포넌트에서도 상태를 관리할 수 있다. 🚩 useState() 사용 흐름 useState()를 사용하는 것은 다음의 세 단계로 이루어진다. import { useState } from "react"; // ⓐ function App() { const [count, setCount] = useState(0); // ⓑ return ( You clicked {count} times setCount(count + 1)}> // ⓒ ); } ..

Shift 2D Grid Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: Element at grid[i][j] moves to grid[i][j + 1]. Element at grid[i][n - 1] moves to grid[i + 1][0]. Element at grid[m - 1][n - 1] moves to grid[0][0]. Return the 2D grid after applying shift operation k times. Example 1: Input: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1 Output: [[..