짝수를 담은 배열, 홀수를 담은 배열 각각 개수를 빈 배열에 넣어주고 반환한다.
import Foundation
func solution(_ num_list:[Int]) -> [Int] {
var num1: [Int] = []
var num2: [Int] = []
var num3: [Int] = []
for i in num_list {
if i % 2 == 0 {
num1.append(i)
} else {
num2.append(i)
}
}
num3.append(num1.count)
num3.append(num2.count)
return num3
}
import Foundation
func solution(_ num_list:[Int]) -> [Int] {
return [num_list.filter{$0 % 2 == 0}.count, num_list.filter{$0 % 2 == 1}.count]
}
빨리 filter와 친해지고 싶다 🔥