문제 요약
뒷 네 자리만 제외하고 전부 마스킹하면 된다. 이를 위해서 startIndex의 위치를 알아내고 문자열의 길이에 맞춰 마스킹된 애스터리스크를 생성하여 출력하고 원본 숫자 네 자리를 출력한다.
해답
func solution(_ phone_number:String) -> String {
let startindex = phone_number.index(phone_number.endIndex, offsetBy: -4)
return String(repeating: "*", count: phone_number.count-4) + phone_number[startindex...]
}
'Algorithm > 프로그래머스' 카테고리의 다른 글
| [프로그래머스 스위프트] 평균 구하기 (0) | 2022.08.24 |
|---|---|
| [프로그래머스 스위프트] 하샤드 수 (0) | 2022.08.24 |
| [프로그래머스 스위프트] 행렬의 덧셈 (0) | 2022.08.24 |
| [프로그래머스 스위프트] x만큼 간격이 있는 n개의 숫자 (0) | 2022.08.24 |
| [프로그래머스 스위프트] 직사각형 별찍기 (0) | 2022.08.24 |