코딩 테스트 109

숫자와 문자가 섞인 문자열 배열 정렬

.sort(({ properties: { name: a = 0 } } = {}, { properties: { name: b = 0 } } = {}) => (a.match(/\d+/) ?? [0])[0] - (b.match(/\d+/) ?? [0])[0]) .sort(({ properties: { name: a = '가' } } = {}, { properties: { name: b = '가' } } = {}) => (a.match(/[가-힣]/) ?? ['가'])[0] > (b.match(/[가-힣]/) ?? ['가'])[0] ? 1 : (a.match(/[가-힣]/) ?? ['가'])[0] < (b.match(/[가-힣]/) ?? ['가'])[0] ? -1 : 0 )

stirling formula(팩토리얼)

https://en.wikipedia.org/wiki/Stirling%27s_approximation Stirling's approximation - Wikipedia From Wikipedia, the free encyclopedia Approximation for factorials Comparison of Stirling's approximation with the factorial In mathematics, Stirling's approximation (or Stirling's formula) is an approximation for factorials. It is a good approximation, le en.wikipedia.org 팩토리얼은 stirling formula에 근사함 수가..

Tree

//! 1진트리 class Tree { //tree의 constructor를 생성 : tree의 자식 노드들을 엘리먼트로 담을 children 배열로 선언 constructor(value) { this.value = value this.children = [] } // 자식 노드 생성 메소드 구현 : new 키워드로 자식 노드를 생성 한 후, children 배열에 push insertNode(value) { const childNode = new Tree(value) this.children.push(childNode) } // tree에서 value값을 탐색하기 위한 메소드 구현 contains(value) { // 현재 노드의 value 값이 찾는 값과 일치한다면 true 반환 if (this.va..

순열, 중복순열, 조합, 중복조합

순열 function solution(arr, n) { let result = [] function DFS(n, tempArr) { if (n === 0) return result.push(tempArr) for (let i = 0; i < arr.length; i++) { if (!tempArr.includes(arr[i])) DFS(n - 1, tempArr.concat(arr[i])); } } DFS(n, []) return result } // n만 주어졌을 때 function solution(n) { let result = [] let N = n function DFS(n, tempArr) { if (n === 0) return result.push(tempArr) for (let i = 1; i