Skip to content

Instantly share code, notes, and snippets.

@o-henry
o-henry / type.ts
Last active October 4, 2022 03:10
// schema validation
import { z } from "zod"
enum Risk {
Low,
Medium,
High,
}
const _CalculateRiskProfile = (age: _Age): Risk => (__Age.parse(age) < 60 ? Risk.Low : Risk.Medium)
@o-henry
o-henry / Stack.js
Created February 26, 2020 02:03
Stack
class Stack {
constructor() {
this._arr = [];
}
push(item) {
this._arr.push(item);
}
pop() {
return this._arr.pop();
}
@o-henry
o-henry / Queue.js
Created February 26, 2020 01:57
Queue
class Queue {
constructor() {
this._arr = [];
}
enqueue(item) {
this._arr.push(item);
}
dequeue() {
return this._arr.shift();
}
@o-henry
o-henry / HashTable.js
Last active February 25, 2020 12:53
Hash-Table
class HashTable{
constructor(size){
this.buckets = new Array(size)
this.size = size
}
hashFunc(key) {
return key.toString().length % this.size;
}
@o-henry
o-henry / QuickSort.js
Last active February 26, 2020 08:45
QuickSort.js
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) {
@o-henry
o-henry / MergeSort.js
Last active February 3, 2020 10:20
MergeSort.js
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);
@o-henry
o-henry / SeletionSort.js
Last active February 3, 2020 05:47
Selection Sort
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]) {