Skip to content

Instantly share code, notes, and snippets.

View mu-hun's full-sized avatar
💡
No Silver Bullet

Mu hun mu-hun

💡
No Silver Bullet
View GitHub Profile
@mu-hun
mu-hun / error.log
Last active May 29, 2020 15:03
Gatsby + SASS 환경에서 CSSO 사용할려고 csso-loader 집어넣는 중..
ERROR #98123 WEBPACK
Generating JavaScript bundles failed
Cannot read property 'line' of undefined
@mu-hun
mu-hun / fibonacciLoop.js
Last active May 21, 2020 13:20
Implement fibonacci with Bottom-Up Style
function fib(n) {
let first = 1, second = 0;
let current;
for (let i = 2; i <= n; i++) {
current = first + second
second = first
first = current
}
return current
}
function nextPermutation(A: number[]) {
let i = A.length - 1
let j = A.length - 1
while (i > 0 && A[i - 1] >= A[i]) i -= 1
if (i === 0) return false
while (A[j] <= A[i - 1]) j -= 1
@mu-hun
mu-hun / string_number.ts
Created May 14, 2020 03:15
string to number or number to string
function strToint(string: string) {
let i = 0;
let num = 0;
let isNeg = false;
const length = string.length;
const zeroCode = '0'.charCodeAt(0);
if (string[0] === '-') {
isNeg = true;
i = 1;
@mu-hun
mu-hun / palindrome.ts
Last active May 13, 2020 12:35
palindrome
function palindrome<T extends string | string[]>(array: T) {
for (let start = 0, end = array.length - 1; start < end; start++, end--) {
if (array[start] !== array[end]) return false
}
return true
}
console.assert(palindrome('HIH'))
console.assert(palindrome('nan nan nan'))
const isEqual = <T extends number | string>(first: T[], second: T[]) =>
first.length === second.length &&
first.findIndex((item, index) => item !== second[index]) === -1;
const isEqualVariableArray = <T>(...arrays: T[][]) => arrays.slice(0, arrays.length - 1).findIndex((array, index) => !isEqual<T>(array, arrays[index+1]))
console.assert(isEqualVariableArray<number>([1, 2], [1, 2], [1, 2]))
function selectionSort(array: number[]) {
for (let last = array.length - 1; last > 0; last--) {
const largest = array.slice(0, last + 1).sort()[last];
const largestIndex = array.findIndex((item) => item === largest);
array[largestIndex] = array[last];
array[last] = largest;
}
return array;
}
@mu-hun
mu-hun / index.ts
Created March 9, 2020 12:39
make dirary files
import { writeFileSync } from 'fs'
const start = 'Thu Oct 31 2019 00:00:00'
const date = new Date(start)
const current = new Date()
const pad = (d: number) => (d < 10 ? '0' + d.toString() : d.toString())
type NumAndPad = { num: number; pad: string }
@mu-hun
mu-hun / reflaltion.md
Created January 24, 2020 22:23
리플렉션 개인정보 취급 방침 및 FAQ

FAQ

이 확장 앱은 어떤 데이터를 저장하나요?

로그인 유지 기능 사용 여부와 계정 데이터를 브라우저 측에 저장합니다.

서브 키
// orginal source: https://repl.it/@stella_sighs/dijkstramedium
const graph = {
start: { A: 5, B: 2 },
A: { C: 4, D: 2 },
B: { A: 8, D: 7 },
C: { D: 6, finish: 3 },
D: { finish: 1 },
finish: {}
}