문자열에서 숫자를 필터링하고 Int로 형 변환을 한 다음 오름차순 정렬을 해준다.
import Foundation
func solution(_ my_string:String) -> [Int] { my_string.compactMap { Int(String($0)) }.sorted() }
import Foundation
func solution(_ my_string:String) -> [Int] {
return my_string.filter { $0.isNumber }.map { Int(String($0))! }.sorted()
}
filter를 사용해 isNumber를 활용해서 문자열에서 숫자를 뽑아낼 수도 있다.