[프로그래머스] 신규 아이디 추천 Swift
프로그래머스 - 신규 아이디 추천
문제 : https://programmers.co.kr/learn/courses/30/lessons/72410
Code :
import Foundation
func solution(_ new_id:String) -> String {
    var s = new_id.lowercased().filter{  $0.isLetter || $0.isNumber || $0 == "-" || $0 == "_" || $0 == "." }.map{String($0)}.joined()
    while s.contains(".."){s = s.replacingOccurrences(of: "..", with: ".")}
    if let a = s.first, a == "."{s.removeFirst()};
    if let a = s.last, a == "."{s.removeLast()}
    if s.isEmpty{ s = "a" }
    if s.count>=16 {
        s = String(s.prefix(15))
        if s.last! == "."{
            s.removeLast()
        }
    }
    while s.count < 3{s += String(s.last!)}
    
    
    return s
}Author And Source
이 문제에 관하여([프로그래머스] 신규 아이디 추천 Swift), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@baekteun/프로그래머스-신규-아이디-추천-Swift저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)