We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💬 문제
[코딩테스트 연습 - 자연수 뒤집어 배열로 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/12932)
💬 풀이
func solution(_ n:Int64) -> [Int] { return Array(String(n)).reversed().map({ Int(String($0))! }) }
💬 알게된 문법
return Array(String(n)).reversed().compactMap({ Int(String($0)) }) // [5, 4, 3, 2, 1] // map과 비교 -> map은 강제 언래핑 또는 옵셔널 바인딩을 해주어야 한다. return Array(String(n)).reversed().map({ Int(String($0))! })
// ✅ [ map과 비교 ] let mapped: [Int?] = possibleNumbers.map { str in Int(str) } // [1, 2, nil, nil, 5] (map은 nil을 포함함) let compactMapped: [Int] = possibleNumbers.compactMap { str in Int(str) } // [1, 2, 5] (compactMap은 nil을 제외)
https://developer.apple.com/documentation/swift/sequence/compactmap(_:)
let numbers = [1, 2, 3, 4] let mapped = numbers.map { Array(repeating: $0, count: $0) } // [[1], [2, 2], [3, 3, 3], [4, 4, 4, 4]] let flatMapped = numbers.flatMap { Array(repeating: $0, count: $0) } // [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
https://developer.apple.com/documentation/swift/sequence/flatmap(_:)-jo2y
The text was updated successfully, but these errors were encountered:
#64 - 자연수 뒤집어 배열로 만들기 문제 풀이
d184722
hwangJi-dev
No branches or pull requests
💬 문제
[코딩테스트 연습 - 자연수 뒤집어 배열로 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/12932)
💬 풀이
💬 알게된 문법
✅ compactMap
https://developer.apple.com/documentation/swift/sequence/compactmap(_:)
✅ flatMap
https://developer.apple.com/documentation/swift/sequence/flatmap(_:)-jo2y
The text was updated successfully, but these errors were encountered: