[Algorithm] Programmers 문자열 정렬하기(2)

Mintaek·2023년 1월 28일
0
post-thumbnail

문제 설명

영어 대소문자로 이루어진 문자열 my_string이 매개변수로 주어질 때, my_string을 모두 소문자로 바꾸고 알파벳 순서대로 정렬한 문자열을 return 하도록 solution 함수를 완성해보세요.

제한 사항

0 < my_string 길이 < 100

입출력 예

my_stringresult
"Bcad""abcd"
"heLLo""ehllo"
"Python""hnopty

풀이

function solution(my_string){
   const answer = my_string.toLowerCase().split('').sort().join('')
   return answer;
}
  • 풀이가 깔끔하지 않은거 같아서 하나 더 줄인 다른 분의 코드를 가져왔다
const solution2 = (s) => [...s.toLowerCase()].sort().join('') 
  • 의미는 같지만 , 전개연산자 안에서 toLowerCase() 메서드를 사용가능 한 것을 처음 알았다
profile
Slow and Steady Wins the Race

0개의 댓글

관련 채용 정보