https://school.programmers.co.kr/learn/courses/30/lessons/12915
function solution(strings, n) {
for (let i = 0; i < strings.length; i++) {
strings[i] = strings[i][n] + strings[i];
}
strings.sort();
for (let i = 0; i < strings.length; i++) {
strings[i] = strings[i].slice(1, strings[i].length);
}
return strings;
}
let word = birthday;
console.log(word[4])
// expected output : h
replace()
메서드 사용법 학습하기, https://hianna.tistory.com/720sort : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
커스터마이징 : https://velog.io/@jakeseo_me/Javascript-Sort%ED%95%A8%EC%88%98%EC%97%90-%EB%8C%80%ED%95%9C-%EC%9E%A1%EC%A7%80%EC%8B%9D#%EC%9E%90%EC%A3%BC-%EC%93%B0%EC%9D%B4%EB%8A%94-%EC%BB%A4%EC%8A%A4%ED%84%B0%EB%A7%88%EC%9D%B4%EC%A7%95
function solution(strings, n) {
// strings 배열
// n 번째 문자열 비교
return strings.sort((s1, s2) => s1[n] === s2[n] ? s1.localeCompare(s2) : s1[n].localeCompare(s2[n]));
}
감사합니다. 이런 정보를 나눠주셔서 좋아요.