일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 러닝타이머
- 서체관리자
- WeatherManager
- 클로저의 캡슐화
- CoreLocation
- MKMapViewDelegate
- SwiftUI Boolean 값
- AnyObject
- App Store Connect
- UIAlertAction
- xcode로 날씨앱 만들기
- Required Reason API
- dispatchsource
- swift
- 영문 개인정보처리방침
- weatherKit
- Protocol
- weak var
- MKMapItem
- Xcode
- addannotation
- CLLocationManagerDelegate
- 한국어 개인정보처리방침
- 러닝기록앱
- RunningTimer
- UICollectionViewFlowLayout
- font book
- Startign Assignments
- Timer
- 단일 책임원칙
Archives
- Today
- Total
VesselWheel
나누어 떨어지는 숫자 배열 본문
문제
풀이
func solution(_ arr:[Int], _ divisor:Int) -> [Int] {
// 매개변수 arr을 divisor로 나눈 나머지가 0으로 필터링 한 후 오름차순(sorted())으로 배열 안에서 정렬
let result = arr.filter{$0 % divisor == 0}.sorted()
// 나누어 떨어지는 element가 없으면 배열 안에 -1을 담아 result로 반환
return result.count == 0 ? [-1] : result
}
Tip 고차함수 filter 참조
https://vesselwheel.tistory.com/103
'Coding Test Practice in Swift' 카테고리의 다른 글
핸드폰 번호 가리기 (0) | 2023.11.23 |
---|---|
음양 더하기 (0) | 2023.11.22 |
서울에서 김서방 찾기 (2) | 2023.11.22 |
콜라츠 추측 (0) | 2023.11.22 |
두 정수 사이의 합 with reduce 함수 (1) | 2023.11.21 |