This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const selectionSort = arr => { | |
let minIndex; | |
let temp; | |
// 데이터가 담긴 배열 전체를 돕니다. | |
for (let i = 0; i < arr.length - 1; i++) { | |
minIndex = i; // 맨 처음부터 확인합니다. | |
for (let j = i + 1; j < arr.length; j++) { | |
// 최소값 위치를 찾습니다. | |
if (arr[j] < arr[minIndex]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mergeSort(unsortedArr) { | |
// Base Case | |
if (unsortedArr.length <= 1) { | |
return unsortedArr | |
} | |
const mid = Math.floor(unsortedArr.length / 2); | |
const left = unsortedArr.slice(0, mid); | |
const right = unsortedArr.slice(mid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function quickSort(array) { | |
if (array.length < 2) return array; | |
const pivot = array[0]; | |
let leftCursor = 1; | |
let rightCursor = array.length - 1; | |
// left Cursor가 rightCursor와 만나는 순간 까지 | |
while(leftCursor <= rightCursor) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HashTable{ | |
constructor(size){ | |
this.buckets = new Array(size) | |
this.size = size | |
} | |
hashFunc(key) { | |
return key.toString().length % this.size; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Queue { | |
constructor() { | |
this._arr = []; | |
} | |
enqueue(item) { | |
this._arr.push(item); | |
} | |
dequeue() { | |
return this._arr.shift(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack { | |
constructor() { | |
this._arr = []; | |
} | |
push(item) { | |
this._arr.push(item); | |
} | |
pop() { | |
return this._arr.pop(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// schema validation | |
import { z } from "zod" | |
enum Risk { | |
Low, | |
Medium, | |
High, | |
} | |
const _CalculateRiskProfile = (age: _Age): Risk => (__Age.parse(age) < 60 ? Risk.Low : Risk.Medium) |