코딩 테스트/알고리즘 공부

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

fullfish 2023. 6. 22. 11:24
.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
)

 

'코딩 테스트 > 알고리즘 공부' 카테고리의 다른 글

가장 큰 자리 숫자 남기고 내림  (0) 2023.05.04
stirling formula(팩토리얼)  (0) 2023.03.26
Tree  (0) 2023.02.06
팩토리얼 factorial  (0) 2022.12.25
순열, 중복순열, 조합, 중복조합  (0) 2022.12.25