[1주 - 5일차] 학습 정리
새로 알아간 것들
// 소수점 반올림 없이 자르기
let numberFormatter = NumberFormatter()
numberFormatter.roundingMode = .floor // 형식을 버림으로 지정
numberFormatter.minimumSignificantDigits = 2 // 자르길 원하는 자릿수
numberFormatter.maximumSignificantDigits = 2
let originalNum = 1.6759402 // 원하는 숫자
let newNum = numberFormatter.string(from: originalNum) // result 1.67
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"))
// ["OOO", "", ""]
// ["OOO"]
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]
Author And Source
이 문제에 관하여([1주 - 5일차] 학습 정리), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@okstring/1주-5일차-학습-정리저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)