새로 알아간 것들
let numberFormatter = NumberFormatter()
numberFormatter.roundingMode = .floor
numberFormatter.minimumSignificantDigits = 2
numberFormatter.maximumSignificantDigits = 2
let originalNum = 1.6759402
let newNum = numberFormatter.string(from: originalNum)
reference
fibonacci
func fibonacci(num: Int) -> Int {
if num == 1 { return 1}
return fibonacci(num: num - 1) + num
}
Components vs split
var str = "OOOXX"
print(str.components(separatedBy: "X"))
print(str.split(separatedBy: "X"))
Swift Closures 에 유용한 Method
reduce
func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Element) throws -> Result) rethrows -> Result
map
func map<T>(_ transform: (Element) throws -> T) rethrows -> [T]
filter
func filter(_ isIncluded: (Self.Element) throws -> Bool) rethrows -> [Self.Element]