This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 배열의 조합 구하기 | |
| /// 순서에 상관없이 같은 요소가 포함되어 있다면, 같은 조합으로 처리 (결국 처음 제공되는 배열 요소들의 순서를 유지한다) | |
| /// - Parameters: | |
| /// - arr: 제공되는 배열 | |
| /// - select: 몇개의 요소를 선택해서 조합할지 결정 | |
| /// - Returns: 제공된 배열에서 select 개를 선택해서 조합된 새 배열 | |
| func getPermutations(_ arr: [Book], select: Int) -> [[Book]] { | |
| var results: [[Book]] = [] | |
| if select == 1 { | |
| return arr.map { [$0] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Int { | |
| /// 숫자 범위에 따라 텍스트 표시 | |
| func readableCount() -> String { | |
| let formatter = NumberFormatter() | |
| formatter.numberStyle = .decimal | |
| formatter.groupingSeparator = "" | |
| formatter.maximumFractionDigits = 1 | |
| switch self { | |
| case _ where self < 1000: | |
| return "\(self)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 배열의 모든 조합 구하기 (순열) | |
| /// 순서에 상관하여 같은 요소라도 순서가 다르면 다른 조합으로 처리 | |
| /// - Parameters: | |
| /// - arr: 제공되는 배열 | |
| /// - select: 몇개의 요소를 선택해서 조합할지 결정 | |
| /// - Returns: 제공된 배열에서 select 개를 선택해서 조합된 새 배열 | |
| func getAllPermutations(_ arr: [Int], select: Int) -> [[Int]] { | |
| var results: [[Int]] = [] | |
| if select == 1 { | |
| return arr.map { [$0] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension NullIterable<E> on Iterable<E> { | |
| E? getFirstOrNull(bool test(E element)) { | |
| try { | |
| return this.firstWhere(test); | |
| } catch (e) { | |
| return null; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// [Page] 배열에서 movies 값만 모아 가져오기. | |
| extension Array where Element == Page { | |
| var movies: [String] { | |
| flatMap { $0.movies } | |
| } | |
| } | |
| /// Page 샘플 | |
| struct Page { | |
| let movies: [String] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // from Node.js 하이 퍼포먼스 | |
| var users = {}; | |
| function getUser(id, next) { | |
| if (users.hasOwnPropoerty(id)) { | |
| if (users[id].hasOwnProperty("data")) { | |
| return next(null, users[id].data); | |
| } | |
| // 아직 값이 없음 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Rest { | |
| static apiBaseUrl = ''; | |
| static getApiHeader({withoutContentType = false} = {}) { | |
| const header = {}; | |
| header['reqVersion'] = 2; | |
| // if (authentic) { | |
| // header['Authorization'] = this.getAuthToken(); | |
| // } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // extends ajax | |
| $.ajax = (($oldAjax) => { | |
| var df = $.Deferred(); | |
| // on fail, retry by creating a new Ajax deferred | |
| function check(self, status) { | |
| console.log("check " + status + " => " + self.retries); | |
| const shouldRetry = status != 'success' && status != 'parsererror'; | |
| if (shouldRetry && self.retries > 0) { | |
| setTimeout(() => { | |
| console.log("retry " + self.retries); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 바인딩 | |
| private var observations: [NSKeyValueObservation] = [] | |
| private var viewModel = ExpenseViewModel() | |
| // 뷰 바인딩 | |
| observations = [ | |
| viewModel.observe(\.price) { | |
| let price = $0 ?? 0.0 | |
| self.updatePriceText(with: price) | |
| self.changesPublisher.onNext(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ExpenseViewModel: NSObject { | |
| @objc dynamic var price = -1.0 | |
| @objc dynamic var title = "" | |
| @objc dynamic var text: String? = nil | |
| } |