From 58dae09c1906f73e020987dec519ffb02c84e90f Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 2 Jan 2025 10:11:04 +0900 Subject: [PATCH 01/24] =?UTF-8?q?remove=20smallest=20number=20/=20?= =?UTF-8?q?=E4=BB=A5=EB=AC=8E=ED=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Array/remove_smallest_number.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 JustDevRae/Array/remove_smallest_number.js diff --git a/JustDevRae/Array/remove_smallest_number.js b/JustDevRae/Array/remove_smallest_number.js new file mode 100644 index 0000000..9b08aa3 --- /dev/null +++ b/JustDevRae/Array/remove_smallest_number.js @@ -0,0 +1,8 @@ +function solution(arr) { + var answer = []; + const minValue = Math.min(...arr); + answer = arr.filter((element) => element > minValue); + if (answer.length === 0) answer.push(-1); + + return answer; +} From d1ddf643f72ae33453a50d81ec7095d0e8c135b8 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 2 Jan 2025 10:18:23 +0900 Subject: [PATCH 02/24] =?UTF-8?q?divisible=20numbers=20array=20/=20?= =?UTF-8?q?=E4=BB=A5=EB=AC=8E=ED=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Array/divisible_numbers_array.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 JustDevRae/Array/divisible_numbers_array.js diff --git a/JustDevRae/Array/divisible_numbers_array.js b/JustDevRae/Array/divisible_numbers_array.js new file mode 100644 index 0000000..77114d0 --- /dev/null +++ b/JustDevRae/Array/divisible_numbers_array.js @@ -0,0 +1,10 @@ +function solution(arr, divisor) { + var answer = []; + + answer = arr.filter((element) => element % divisor === 0); + answer.sort((a, b) => a - b); + + if (answer.length === 0) answer.push(-1); + + return answer; +} From 8d7fe56ae64c232afc3c9c76daf9c4708dc95549 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 2 Jan 2025 10:26:19 +0900 Subject: [PATCH 03/24] =?UTF-8?q?duplicate=20number=20count=20/=20?= =?UTF-8?q?=E6=B9=B2=EA=B3=97=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Array/duplicate_number_count.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 JustDevRae/Array/duplicate_number_count.js diff --git a/JustDevRae/Array/duplicate_number_count.js b/JustDevRae/Array/duplicate_number_count.js new file mode 100644 index 0000000..ccebe4d --- /dev/null +++ b/JustDevRae/Array/duplicate_number_count.js @@ -0,0 +1,6 @@ +function solution(array, n) { + var answer = 0; + answer = array.filter((el) => el === n); + + return answer.length; +} From d7f63b08ee496dbe8237e30884eeba0211eef0bd Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 2 Jan 2025 10:36:51 +0900 Subject: [PATCH 04/24] =?UTF-8?q?matrix=20addition=20/=20=E4=BB=A5?= =?UTF-8?q?=EB=AC=8E=ED=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Array/matrix_addition.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 JustDevRae/Array/matrix_addition.js diff --git a/JustDevRae/Array/matrix_addition.js b/JustDevRae/Array/matrix_addition.js new file mode 100644 index 0000000..6a004ad --- /dev/null +++ b/JustDevRae/Array/matrix_addition.js @@ -0,0 +1,12 @@ +function solution(arr1, arr2) { + var answer = [[]]; + + for (let i = 0; i < arr1.length; i++) { + answer[i] = []; + for (let j = 0; j < arr1[i].length; j++) { + answer[i][j] = arr1[i][j] + arr2[i][j]; + } + } + + return answer; +} From 36b4d80708558d861f8cc2ea9f8a60edd9fd5276 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 2 Jan 2025 10:40:54 +0900 Subject: [PATCH 05/24] =?UTF-8?q?array=20element=20length=20/=20=E6=B9=B2?= =?UTF-8?q?=EA=B3=97=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Array/array_element_length.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 JustDevRae/Array/array_element_length.js diff --git a/JustDevRae/Array/array_element_length.js b/JustDevRae/Array/array_element_length.js new file mode 100644 index 0000000..197cc15 --- /dev/null +++ b/JustDevRae/Array/array_element_length.js @@ -0,0 +1,6 @@ +function solution(strlist) { + var answer = []; + answer = strlist.map((str) => str.length); + + return answer; +} From bab0b850a6fe7afb07add0a6abac02bb78caa9c2 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 2 Jan 2025 10:52:12 +0900 Subject: [PATCH 06/24] =?UTF-8?q?rotate=20array=20/=20=E6=B9=B2=EA=B3=97?= =?UTF-8?q?=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Array/rotate_array.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 JustDevRae/Array/rotate_array.js diff --git a/JustDevRae/Array/rotate_array.js b/JustDevRae/Array/rotate_array.js new file mode 100644 index 0000000..4609967 --- /dev/null +++ b/JustDevRae/Array/rotate_array.js @@ -0,0 +1,13 @@ +function solution(numbers, direction) { + var answer = []; + + if (direction == "left") { + numbers.push(numbers.shift()); + } + + if (direction == "right") { + numbers.unshift(numbers.pop()); + } + + return (answer = numbers); +} From c8b3d17beef32bf1275fc39091a2314933f54a55 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 2 Jan 2025 10:53:32 +0900 Subject: [PATCH 07/24] =?UTF-8?q?slice=20array=20/=20=E6=B9=B2=EA=B3=97?= =?UTF-8?q?=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Array/slice_array.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 JustDevRae/Array/slice_array.js diff --git a/JustDevRae/Array/slice_array.js b/JustDevRae/Array/slice_array.js new file mode 100644 index 0000000..785db74 --- /dev/null +++ b/JustDevRae/Array/slice_array.js @@ -0,0 +1,5 @@ +function solution(numbers, num1, num2) { + var answer = []; + + return (answer = numbers.slice(num1, num2 + 1)); +} From 45ce6e5ddef9f2d8419aba05a55260d128acc9d5 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 2 Jan 2025 21:12:42 +0900 Subject: [PATCH 08/24] array algorithm md file --- JustDevRae/Array/array_algorithm.md | 190 ++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 JustDevRae/Array/array_algorithm.md diff --git a/JustDevRae/Array/array_algorithm.md b/JustDevRae/Array/array_algorithm.md new file mode 100644 index 0000000..b97a2ea --- /dev/null +++ b/JustDevRae/Array/array_algorithm.md @@ -0,0 +1,190 @@ +# 배열 알고리즘 & 시간복잡도 정리 + +## 1. 배열 관련 내장 함수 + +### 1.1 map +- 설명: 각 요소에 함수를 적용하여 새 배열을 만듭니다. +- 시간복잡도: O(n) +- 예시 코드: + ```javascript + const arr = [1, 2, 3]; + const doubled = arr.map(x => x * 2); + console.log(doubled); // [2, 4, 6] + ``` + +### 1.2 filter +- 설명: 조건을 충족하는 요소만으로 새 배열을 만듭니다. +- 시간복잡도: O(n) +- 예시 코드: + ```javascript + const arr = [1, 2, 3, 4]; + const evens = arr.filter(x => x % 2 === 0); + console.log(evens); // [2, 4] + ``` + +### 1.3 reduce +- 설명: 배열을 하나의 값으로 축소합니다. +- 시간복잡도: O(n) +- 예시 코드: + ```javascript + const arr = [1, 2, 3, 4]; + const sum = arr.reduce((acc, cur) => acc + cur, 0); + console.log(sum); // 10 + ``` + +### 1.4 forEach +- 설명: 배열의 각 요소에 대해 제공된 함수를 실행합니다. +- 시간복잡도: O(n) +- 예시 코드: + ```javascript + const arr = [1, 2, 3]; + arr.forEach(x => console.log(x)); + ``` + +### 1.5 push +- 설명: 배열의 끝에 하나 이상의 요소를 추가합니다. +- 시간복잡도: O(1) +- 예시 코드: + ```javascript + const arr = [1, 2, 3]; + arr.push(4); + console.log(arr); // [1, 2, 3, 4] + ``` + +### 1.6 pop +- 설명: 배열의 마지막 요소를 제거합니다. +- 시간복잡도: O(1) +- 예시 코드: + ```javascript + const arr = [1, 2, 3, 4]; + arr.pop(); + console.log(arr); // [1, 2, 3] + ``` + +### 1.7 unshift +- 설명: 배열의 시작 부분에 하나 이상의 요소를 추가합니다. +- 시간복잡도: O(n) +- 예시 코드: + ```javascript + const arr = [1, 2, 3]; + arr.unshift(0); + console.log(arr); // [0, 1, 2, 3] + ``` + +### 1.8 shift +- 설명: 배열의 첫 번째 요소를 제거합니다. +- 시간복잡도: O(n) +- 예시 코드: + ```javascript + const arr = [1, 2, 3]; + arr.shift(); + console.log(arr); // [2, 3] + ``` + +## 2. 검색 알고리즘 + +### 2.1 선형 검색 +- 설명: 배열의 각 요소를 순차적으로 확인하여 목표값을 찾습니다. +- 시간복잡도: O(n) +- 예시 코드: + ```javascript + const arr = [1, 2, 3, 4, 5]; + console.log(arr.indexOf(3)); // 2 + console.log(arr.find(x => x > 3)); // 4 + ``` + +### 2.2 이진 검색 +- 설명: 정렬된 배열에서 중간값을 기준으로 탐색 범위를 좁혀가며 목표값을 찾습니다. +- 시간복잡도: O(log n) +- 예시 코드: + ```javascript + function binarySearch(arr, target) { + let left = 0; + let right = arr.length - 1; + while (left <= right) { + const mid = Math.floor((left + right) / 2); + if (arr[mid] === target) return mid; + if (arr[mid] < target) left = mid + 1; + else right = mid - 1; + } + return -1; + } + + const arr = [1, 2, 3, 4, 5]; + console.log(binarySearch(arr, 3)); // 2 + ``` + +## 3. 정렬 알고리즘 + +### 3.1 기본 정렬 +- 설명: 배열의 요소를 사전순 또는 사용자 정의 순서에 따라 정렬합니다. +- 시간복잡도: 평균 O(n log n) +- 예시 코드: + ```javascript + const arr = [4, 2, 5, 1, 3]; + arr.sort((a, b) => a - b); // [1, 2, 3, 4, 5] + ``` + +### 3.2 버블 정렬 +- 설명: 인접한 두 요소를 비교하여 정렬합니다. +- 시간복잡도: O(n^2) +- 예시 코드: + ```javascript + function bubbleSort(arr) { + for (let i = 0; i < arr.length; i++) { + for (let j = 0; j < arr.length - i - 1; j++) { + if (arr[j] > arr[j + 1]) { + [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; + } + } + } + return arr; + } + + const arr = [4, 2, 5, 1, 3]; + console.log(bubbleSort(arr)); // [1, 2, 3, 4, 5] + ``` + +### 3.3 퀵 정렬 +- 설명: 기준 값을 정하고 이를 기준으로 배열을 분할하여 정렬합니다. +- 시간복잡도: 평균 O(n log n) +- 예시 코드: + ```javascript + function quickSort(arr) { + if (arr.length <= 1) return arr; + const pivot = arr[0]; + const left = arr.slice(1).filter(x => x < pivot); + const right = arr.slice(1).filter(x => x >= pivot); + return [...quickSort(left), pivot, ...quickSort(right)]; + } + + const arr = [4, 2, 5, 1, 3]; + console.log(quickSort(arr)); // [1, 2, 3, 4, 5] + ``` + +### 3.4 병합 정렬 +- 설명: 배열을 반으로 나누어 정렬한 뒤 병합합니다. +- 시간복잡도: O(n log n) +- 예시 코드: + ```javascript + function mergeSort(arr) { + if (arr.length <= 1) return arr; + const mid = Math.floor(arr.length / 2); + const left = mergeSort(arr.slice(0, mid)); + const right = mergeSort(arr.slice(mid)); + + function merge(left, right) { + const result = []; + while (left.length && right.length) { + if (left[0] < right[0]) result.push(left.shift()); + else result.push(right.shift()); + } + return [...result, ...left, ...right]; + } + + return merge(left, right); + } + + const arr = [4, 2, 5, 1, 3]; + console.log(mergeSort(arr)); // [1, 2, 3, 4, 5] + ``` \ No newline at end of file From 38a1f649b5b47fa82455b07d1ec3a5e4203a85be Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 9 Jan 2025 17:13:30 +0900 Subject: [PATCH 09/24] =?UTF-8?q?reverse=20string=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Stack/reverse_string.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 JustDevRae/Stack/reverse_string.js diff --git a/JustDevRae/Stack/reverse_string.js b/JustDevRae/Stack/reverse_string.js new file mode 100644 index 0000000..003d086 --- /dev/null +++ b/JustDevRae/Stack/reverse_string.js @@ -0,0 +1,10 @@ +function solution(my_string) { + var answer = ""; + const string = [...my_string]; + + for (let i = 0; i < my_string.length; i++) { + answer += string.pop(); + } + + return answer; +} From 8219e21e0be0d6b0abfe7deff33d3d83159a811c Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 9 Jan 2025 17:16:05 +0900 Subject: [PATCH 10/24] =?UTF-8?q?control=20Z=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Stack/control_Z.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 JustDevRae/Stack/control_Z.js diff --git a/JustDevRae/Stack/control_Z.js b/JustDevRae/Stack/control_Z.js new file mode 100644 index 0000000..44fba87 --- /dev/null +++ b/JustDevRae/Stack/control_Z.js @@ -0,0 +1,15 @@ +function solution(s) { + var answer = 0; + let Z = 0; + const controlArray = s.split(" "); + for (let i = 0; i < controlArray.length; i++) { + if (controlArray[i] == "Z") { + answer -= Z; + continue; + } + answer += Number(controlArray[i]); + Z = Number(controlArray[i]); + } + + return answer; +} From 3654602000d41a18b56e62eb798697ebff549775 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 9 Jan 2025 17:24:06 +0900 Subject: [PATCH 11/24] =?UTF-8?q?dart=20game=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Stack/dart_game.js | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 JustDevRae/Stack/dart_game.js diff --git a/JustDevRae/Stack/dart_game.js b/JustDevRae/Stack/dart_game.js new file mode 100644 index 0000000..7b67c10 --- /dev/null +++ b/JustDevRae/Stack/dart_game.js @@ -0,0 +1,41 @@ +function solution(dartResult) { + var answer = 0; + const dartResultArray = dartResult.match(/\d+|[SDT]|\#|\*/g); + const stack = []; + let value; + + for (str of dartResultArray) { + if (str === "S") { + value = stack.pop(); + stack.push(value); + } else if (str === "D") { + value = stack.pop(); + stack.push(value * value); + } else if (str === "T") { + value = stack.pop(); + stack.push(value * value * value); + } else if (str === "*") { + let firtPopValue = stack.pop(); + firtPopValue *= 2; + let secondPopValue = stack.pop(); + if (secondPopValue === undefined) { + stack.push(firtPopValue); + } else { + secondPopValue *= 2; + stack.push(secondPopValue); + stack.push(firtPopValue); + } + } else if (str === "#") { + value = stack.pop(); + stack.push(value * -1); + } else { + stack.push(Number(str)); + } + } + + for (element of stack) { + answer += element; + } + + return answer; +} From 1e2f2b0258a534e3050b105ba2539156580a037c Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 9 Jan 2025 17:38:31 +0900 Subject: [PATCH 12/24] =?UTF-8?q?valid=20parentheses=20/=20=EC=A4=91?= =?UTF-8?q?=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Stack/valid_parentheses.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 JustDevRae/Stack/valid_parentheses.js diff --git a/JustDevRae/Stack/valid_parentheses.js b/JustDevRae/Stack/valid_parentheses.js new file mode 100644 index 0000000..14767b2 --- /dev/null +++ b/JustDevRae/Stack/valid_parentheses.js @@ -0,0 +1,16 @@ +function solution(s) { + const stack = []; + for (const c of s) { + if (c === "(") { + stack.push(c); + } else if (c === ")") { + if (stack.length === 0) { + continue; + } else { + stack.pop(); + } + } + } + + return stack.length === 0; +} From a4143c9bbcdde011ce903f15ec42ad4c373a2e6d Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Thu, 9 Jan 2025 17:45:05 +0900 Subject: [PATCH 13/24] =?UTF-8?q?crane=20claw=20game=20/=20=EC=A4=91?= =?UTF-8?q?=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Stack/crane_claw_game.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 JustDevRae/Stack/crane_claw_game.js diff --git a/JustDevRae/Stack/crane_claw_game.js b/JustDevRae/Stack/crane_claw_game.js new file mode 100644 index 0000000..ab28cd5 --- /dev/null +++ b/JustDevRae/Stack/crane_claw_game.js @@ -0,0 +1,23 @@ +function solution(board, moves) { + let answer = 0; + const stack = []; + + for (let move of moves) { + for (let i = 0; i < board.length; i++) { + if (board[i][move - 1] !== 0) { + let doll = board[i][move - 1]; + board[i][move - 1] = 0; + + if (stack.length > 0 && stack[stack.length - 1] === doll) { + stack.pop(); + answer += 2; + } else { + stack.push(doll); + } + break; + } + } + } + + return answer; +} From 77e2e3078d1baf9da0c7cc61345383ea34d0c30c Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Wed, 15 Jan 2025 10:00:27 +0900 Subject: [PATCH 14/24] =?UTF-8?q?pair=20count=20/=20=E6=B9=B2=EA=B3=97?= =?UTF-8?q?=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Queue/pair_count.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 JustDevRae/Queue/pair_count.js diff --git a/JustDevRae/Queue/pair_count.js b/JustDevRae/Queue/pair_count.js new file mode 100644 index 0000000..19f39ac --- /dev/null +++ b/JustDevRae/Queue/pair_count.js @@ -0,0 +1,13 @@ +function solution(n) { + var answer = 0; + + // 1부터 n까지 숫자를 확인 + for (let i = 1; i <= n; i++) { + // i가 n의 약수인지 확인 + if (n % i === 0) { + // i가 n의 약수인지 확인 + answer++; + } + } + return answer; +} From c0967b78f1e2eea082ad2be3679e821d5e0b7043 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Wed, 15 Jan 2025 10:21:52 +0900 Subject: [PATCH 15/24] =?UTF-8?q?find=20point=20position=20/=20=E6=B9=B2?= =?UTF-8?q?=EA=B3=97=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Queue/find_point_position.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 JustDevRae/Queue/find_point_position.js diff --git a/JustDevRae/Queue/find_point_position.js b/JustDevRae/Queue/find_point_position.js new file mode 100644 index 0000000..4f16fad --- /dev/null +++ b/JustDevRae/Queue/find_point_position.js @@ -0,0 +1,10 @@ +function solution(dot) { + var answer = 0; + + if (dot[0] > 0 && dot[1] > 0) answer = 1; + if (dot[0] < 0 && dot[1] > 0) answer = 2; + if (dot[0] < 0 && dot[1] < 0) answer = 3; + if (dot[0] > 0 && dot[1] < 0) answer = 4; + + return answer; +} From d2dc9af92d9c048c6932820e0eb12eb07b94cc29 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Wed, 15 Jan 2025 11:07:05 +0900 Subject: [PATCH 16/24] =?UTF-8?q?login=20success=20/=20=E6=B9=B2=EA=B3=97?= =?UTF-8?q?=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Queue/login_success.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 JustDevRae/Queue/login_success.js diff --git a/JustDevRae/Queue/login_success.js b/JustDevRae/Queue/login_success.js new file mode 100644 index 0000000..c3ccabc --- /dev/null +++ b/JustDevRae/Queue/login_success.js @@ -0,0 +1,16 @@ +function solution(id_pw, db) { + var answer = ""; + for (let i = 0; i < db.length; i++) { + if (id_pw[0] === db[i][0]) { + if (id_pw[1] === db[i][1]) { + answer = "login"; + break; + } + answer = "wrong pw"; + break; + } else { + answer = "fail"; + } + } + return answer; +} From 5928dbdbf88dd0be86444f07fb4763496dd99642 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Fri, 17 Jan 2025 09:27:00 +0900 Subject: [PATCH 17/24] =?UTF-8?q?card=20bundle=20/=20=E4=BB=A5=EB=AC=8E?= =?UTF-8?q?=ED=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Queue/card_bundle.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 JustDevRae/Queue/card_bundle.js diff --git a/JustDevRae/Queue/card_bundle.js b/JustDevRae/Queue/card_bundle.js new file mode 100644 index 0000000..1db6617 --- /dev/null +++ b/JustDevRae/Queue/card_bundle.js @@ -0,0 +1,15 @@ +function solution(cards1, cards2, goal) { + var answer = ""; + for (let word of goal) { + if (word == cards1[0]) { + cards1.shift(); + } else if (word == cards2[0]) { + cards2.shift(); + } else { + answer = "No"; + break; + } + } + + return (answer = "Yes"); +} From 0d2f982d5153a47e72ba9c404522df36c6243e10 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Fri, 17 Jan 2025 10:13:36 +0900 Subject: [PATCH 18/24] =?UTF-8?q?make=20hamburger=20/=20=E4=BB=A5=EB=AC=8E?= =?UTF-8?q?=ED=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Queue/make_hamburger.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 JustDevRae/Queue/make_hamburger.js diff --git a/JustDevRae/Queue/make_hamburger.js b/JustDevRae/Queue/make_hamburger.js new file mode 100644 index 0000000..bda6c56 --- /dev/null +++ b/JustDevRae/Queue/make_hamburger.js @@ -0,0 +1,20 @@ +function solution(ingredient) { + const burger = []; + let answer = 0; + for (let i of ingredient) { + burger.push(i); + + if ( + burger.length >= 4 && + burger[burger.length - 4] === 1 && + burger[burger.length - 3] === 2 && + burger[burger.length - 2] === 3 && + burger[burger.length - 1] === 1 + ) { + burger.splice(burger.length - 4, 4); + answer++; + } + } + + return answer; +} From df8ffd4a1c359f0672ed659a62ecf4f061d1311d Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Fri, 17 Jan 2025 12:02:46 +0900 Subject: [PATCH 19/24] =?UTF-8?q?process=20/=20=EC=8B=AC=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Queue/process.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 JustDevRae/Queue/process.js diff --git a/JustDevRae/Queue/process.js b/JustDevRae/Queue/process.js new file mode 100644 index 0000000..fcc601e --- /dev/null +++ b/JustDevRae/Queue/process.js @@ -0,0 +1,20 @@ +function solution(priorities, location) { + var answer = 0; + const queue = priorities.map((priority, index) => ({ priority, index })); + + while (queue.length > 0) { + const current = queue.shift(); + + const highPriority = queue.some((item) => item.priority > current.priority); + + if (highPriority) { + queue.push(current); + } else { + answer++; + + if (current.index === location) { + return answer; + } + } + } +} From 281c961a83defd20766c050b7e21e595d8c546eb Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Sat, 25 Jan 2025 10:43:24 +0900 Subject: [PATCH 20/24] =?UTF-8?q?morse=20code=20/=20=E6=B9=B2=EA=B3=97?= =?UTF-8?q?=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Hash/morse_code.js | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 JustDevRae/Hash/morse_code.js diff --git a/JustDevRae/Hash/morse_code.js b/JustDevRae/Hash/morse_code.js new file mode 100644 index 0000000..5d70273 --- /dev/null +++ b/JustDevRae/Hash/morse_code.js @@ -0,0 +1,37 @@ +function solution(letter) { + var answer = ""; + const morse = { + ".-": "a", + "-...": "b", + "-.-.": "c", + "-..": "d", + ".": "e", + "..-.": "f", + "--.": "g", + "....": "h", + "..": "i", + ".---": "j", + "-.-": "k", + ".-..": "l", + "--": "m", + "-.": "n", + "---": "o", + ".--.": "p", + "--.-": "q", + ".-.": "r", + "...": "s", + "-": "t", + "..-": "u", + "...-": "v", + ".--": "w", + "-..-": "x", + "-.--": "y", + "--..": "z", + }; + const str = letter.split(" "); + + for (const s of str) { + answer += morse[s]; + } + return answer; +} From 51c45acea882c9447a6d44d7e9ac010b895f3a03 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Sat, 25 Jan 2025 10:46:05 +0900 Subject: [PATCH 21/24] =?UTF-8?q?make=20B=20with=20A=20/=20=E6=B9=B2?= =?UTF-8?q?=EA=B3=97=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Hash/make_B_with_A.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 JustDevRae/Hash/make_B_with_A.js diff --git a/JustDevRae/Hash/make_B_with_A.js b/JustDevRae/Hash/make_B_with_A.js new file mode 100644 index 0000000..2ce90bb --- /dev/null +++ b/JustDevRae/Hash/make_B_with_A.js @@ -0,0 +1,21 @@ +function solution(before, after) { + var answer = 0; + const beforeCount = {}; + const afterCount = {}; + + for (const char of before) { + beforeCount[char] = (beforeCount[char] || 0) + 1; + } + + for (const char of after) { + afterCount[char] = (afterCount[char] || 0) + 1; + } + + for (const key in beforeCount) { + if (beforeCount[key] !== afterCount[key]) { + return (answer = 0); + } + } + + return (answer = 1); +} From 40ee840009ba14f5b6de44b647860fd8e27d24d9 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Sat, 25 Jan 2025 10:48:06 +0900 Subject: [PATCH 22/24] =?UTF-8?q?setting=20order=20care=20/=20=E6=B9=B2?= =?UTF-8?q?=EA=B3=97=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Hash/setting_order_care.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 JustDevRae/Hash/setting_order_care.js diff --git a/JustDevRae/Hash/setting_order_care.js b/JustDevRae/Hash/setting_order_care.js new file mode 100644 index 0000000..c90c316 --- /dev/null +++ b/JustDevRae/Hash/setting_order_care.js @@ -0,0 +1,10 @@ +function solution(emergency) { + const sorted = [...emergency].sort((a, b) => b - a); + const rankMap = new Map(); + + sorted.forEach((value, index) => { + rankMap.set(value, index + 1); + }); + + return emergency.map((value) => rankMap.get(value)); +} From f9ab318f6cdd85c5d983c448aed5243eecd61e64 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Sat, 25 Jan 2025 10:51:38 +0900 Subject: [PATCH 23/24] =?UTF-8?q?not=20finish=20runner=20/=20=E4=BB=A5?= =?UTF-8?q?=EB=AC=8E=ED=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Hash/not_finish_runner.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 JustDevRae/Hash/not_finish_runner.js diff --git a/JustDevRae/Hash/not_finish_runner.js b/JustDevRae/Hash/not_finish_runner.js new file mode 100644 index 0000000..e8026cc --- /dev/null +++ b/JustDevRae/Hash/not_finish_runner.js @@ -0,0 +1,21 @@ +function solution(participant, completion) { + const obj = {}; + + for (const p of participant) { + if (obj[p]) { + obj[p] += 1; + } else { + obj[p] = 1; + } + } + + for (const c of completion) { + obj[c] -= 1; + } + + for (const key in obj) { + if (obj[key] > 0) { + return key; + } + } +} From 8f38987af3a11f0aae0336c99e0bdff6faf49af7 Mon Sep 17 00:00:00 2001 From: JustDevRae Date: Sat, 25 Jan 2025 11:00:18 +0900 Subject: [PATCH 24/24] =?UTF-8?q?rank=20order=20/=20=E6=B9=B2=EA=B3=97?= =?UTF-8?q?=ED=81=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JustDevRae/Hash/rank_order.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 JustDevRae/Hash/rank_order.js diff --git a/JustDevRae/Hash/rank_order.js b/JustDevRae/Hash/rank_order.js new file mode 100644 index 0000000..8d33d58 --- /dev/null +++ b/JustDevRae/Hash/rank_order.js @@ -0,0 +1,6 @@ +function solution(score) { + const averages = score.map(([english, math]) => (english + math) / 2); + const sortedAverages = [...averages].sort((a, b) => b - a); + + return averages.map((avg) => sortedAverages.indexOf(avg) + 1); +}