[프로그래머스] 문자열 내 마음대로 정렬하기😥

GoGoDev·2021년 6월 30일
0

Programmers Lv.1🌱

목록 보기
44/46

https://programmers.co.kr/learn/courses/30/lessons/12915

function solution(strings, n) {    
    return strings.sort((a,b) => a[n] === b[n] ? a.localeCompare(b) : a[n].localeCompare(b[n]));
}

String.localeCompare(String)

localeCompare이란

// The letter "a" is before "c" yielding a negative value
'a'.localeCompare('c'); // -2 or -1 (or some other negative value)

// Alphabetically the word "check" comes after "against" yielding a positive value
'check'.localeCompare('against'); // 2 or 1 (or some other positive value)

// "a" and "a" are equivalent yielding a neutral value of zero
'a'.localeCompare('a'); // 0
profile
🐣차근차근 무럭무럭🐣

0개의 댓글