저장을 습관화

프로그래머스 LV.0 문자열 정렬하기 (2) 본문

코딩 테스트/프로그래머스 - 자바스크립트

프로그래머스 LV.0 문자열 정렬하기 (2)

ctrs 2023. 9. 20. 17:26

프로그래머스 LV.0 문자열 정렬하기 (2)

https://school.programmers.co.kr/learn/courses/30/lessons/120911

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

1. 문제 명

문자열 정렬하기 (2)


2. 문제 설명

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


3. 제한 사항

- 0 < my_string 길이 < 100


4. 예시

my_string result
"Bcad" "abcd"
"heLLo" "ehllo"
"Python" "hnopty"


5. 기본 제공 코드

function solution(my_string) {
    var answer = '';
    return answer;
}


6. 제출한 내 답

const solution = (my_string) => {
  return my_string.toLowerCase().split("").sort().join("");
};

 

6-2. VSC에 작성한 내용

const solution = (my_string) => {
  return my_string.toLowerCase().split("").sort().join("");
};

// 테스트
console.log(solution("Bcad"));
console.log(solution("heLLo"));
console.log(solution("Python"));


7. 특이사항

없음


8. 다른 사람이 작성한 답

8-1. 전개연산자

function solution(s) {
    return [...s.toLowerCase()].sort().join('')
}