-
[프로그래머스 level.1] slice 스파르타 예습알고리즘 2023. 6. 20. 11:33
문자열 내맘대로 정렬하기
function solution(strings, n) { var answer = []; 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) } return strings; }
문자열 자르는 메서드를 slice()를 썼는데 substr() , subString() 얘네들도 slice()랑 똑같이 작용하고 인자도 똑같은 모습으로 받는것 같아서 slice() 하나만 기억하려고 한다.
스파르타에서 풀었던 문제라서 양심에 찔린다.
나중에 반복문 없애는거 한번 리팩토링 해볼까 생각의 생각만 하는중
'알고리즘' 카테고리의 다른 글
[프로그래머스 level.1] join(), split() (0) 2023.06.21 [프로그래머스 level.1] 내림차순정렬, 아스키코드 변환 (0) 2023.06.21 [프로그래머스 level.1] filter , includes (0) 2023.06.20 [프로그래머스 level.1] 이중반복문, 중복제거, 정렬 (0) 2023.06.20 [프로그래머스 level.1] 06.19 (0) 2023.06.19