본문 바로가기

Skill Stacks/Javascript27

Udemy - Javascript - 재귀 문제풀이 Udemy - Javascript - 재귀 문제풀이 Power() 거듭제곱을 재귀로 만든다 function power(num1, num2) { if (num2 === 0) return 1; return num1 * power(num1, num2 - 1) } num2 가 0이면 1을 반환한다 예) 2 ^ 0 = 1 / 4 ^ 0 = 1 num2가 0이 될때까지 return num1 * power(num1, num2 - 1)를 call stack에 넣어준다 num2가 0이 되면 if (num2 === 0) return 1;을 통해 1을 반환한다 call stack에 넣어둔 만큼 num1을 power(num1, num2 - 1)과 곱하면 결과값이 나온다 Factorial() 팩토리얼을 계산 하는 것이다 주어진.. 2023. 1. 11.
Udemy - Javascript - 재귀 Udemy - Javascript - 재귀 재귀 (Recursion) 재귀는 자기 자신을 부르는 과정, (Javascript 같은 경우 함수) 이다 함수가 함수를 부르는 것이다 재귀 함수는 많은 곳에서 쓰인다 JSON.parse / JSON.stringify document.getElementById 그리고 DOM 등 많은 div가 있는데, 그것을 찾기 위해 재귀 함수를 사용할 수도 있다 더 복잡한 자료구조를 해결할 때 유용할 수 있다 iteration보다 더 깔끔할 대체자가 될 수 있다 스택 호출하기 Call Stack 스택 자료 구조다 (스택은 LIFO - Last In First Out) 함수가 적용될 때마다 Call Stack 위에 쌓이게 된다 (PUSH) 그리고 JavaScript가 return.. 2023. 1. 10.
5.3_Javascript - Sliding Window 문제풀이 Udemy - Javascript - Sliding Window Sliding Window - maxSubarraySum Given an array of integers and a number, write a function called maxSubarraySum, which finds the maximum sum of a subarray with the length of the number passed to the function. Note that a subarray must consist of consecutive elements from the original array. In the first example below, [100, 200, 300] is a subarray of the origi.. 2023. 1. 7.
5.2_Javascript - Multiple Pointers 문제풀이 Udemy - Javascript - Multiple Pointers Multiple Pointers - averagePair Multiple Pointers - averagePair Write a function called averagePair. Given a sorted array of integers and a target average, determine if there is a pair of values in the array where the average of the pair equals the target average. There may be more than one pair that matches the average target. Bonus Constraints: Time: O(N).. 2023. 1. 7.
5.1_Javascript - Frequency Counter 문제풀이 Udemy - Javascript - Frequency Counter Frequency Counter Write a function called sameFrequency. Given two positive integers, find out if the two numbers have the same frequency of digits. Your solution MUST have the following complexities: Time: O(N) Sample Input: sameFrequency(182,281) // true sameFrequency(34,14) // false sameFrequency(3589578, 5879385) // true sameFrequency(22,222) // false s.. 2023. 1. 7.
4_Udemy - Javascript 일반적인 문제풀이 패턴 Udemy - Javascript 일반적인 문제풀이 패턴 빈도수 세기 패턴 다중의 입력값들을 비교할 때 유용 배열을 이용하는 것이 아닌 / 주어진 입력값을 객체 ({}) 에 넣고, 문제를 해결하는 것이다 function anagram(word1, word2) { if (word1.length !== word2.length) { return false } else if (word1.length === 0 & word2.length === 0) { return true } let anagramObject1 = {} let anagramObject2 = {} for (let word = 0; word < word1.length ; word++) { if (word1[word] in anagramObject1).. 2023. 1. 6.
3_Javascript - 문제 해결 접근법 Udemy - Javascript 문제 해결 접근법 알고리즘이란? 특정한 작업을 끝내기 위한 과정 또는 단계다 알고리즘 풀이를 더 잘 하기 문제를 해결하기 위해 계획을 짜는 것 일반적인 문제 해결 패턴을 파악하는 것 문제 해결 문제의 이해 코드를 직접 치기 전에, 문제를 이해하는 것이 중요하다 문제를 내가 이해할 수 있도록 정리를 한다 문제에 어떤 입력값이 들어가는가? 내가 짠 코드를 통해 어떤 결과가 나오는지 생각한다 입력값이 있으면, 결과가 잘 나오는가? 데이터를 어떻게 표시할 것인가? 구체적 예제들 쉬운 예제들을 먼저 써놓은다 그리고 그보다 더 어려운 예제들로 진행한다 입력값이 없는 상태에서도 어떻게 결과나 나오는지 생각해본다 유효하지 않은 입력값을 넣어본다 세부 분석 문제에 대한 단계들을 실제로 .. 2023. 1. 5.
2_Javascript - 객체와 배열의 빅오 Udemy - Javascript 객체의 빅오 let instructor = { firstName : "Kelly", isInstructor: true, favoriteNumbers: [1,2,3,4], } Key와 Value가 있다 객체를 사용할 때 정렬이 필요하지 않을 때 데이터를 빠르게 접근을 하거나, 추가를 하거나, 삭제를 할 때 객체의 빅오 추가하기 (Insertion) : O(1) 삭제하기 (Removal) : O(1) 찾기 (Searching) : O(N) Value를 찾는 것 데이터에 접근하기 (Access) : O(1) 객체의 메서드 (Object Methods) object.keys : O(N) object.values : O(N) object.entries : O(N) hasOwnPr.. 2023. 1. 5.
1_Javascript - Big O Notation Udemy - Javascript Big O Notation 다양한 코드가 있으면, 코드의 성능을 보여주는 것 데이터가 더 많아질 수록, 코드의 성능이 매우 중요해진다 성능이 좋은 코드? addUpTo 예시) n 이 주어지면 1부터 n까지의 합을 구하는 것4 for문을 사용하기 function addUpTo (n) { let total = 0; for (let i = 1; i 2023. 1. 4.