Last active
December 27, 2020 02:26
-
-
Save SlappyAUS/512d643554c51303c534a0b992d502c3 to your computer and use it in GitHub Desktop.
Array Filtering #swift #array #filter
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
| // Filter array to only the drinks in the last 24 hours. | |
| private func filterDrinks(drinks: [Drink]) -> [Drink] { | |
| // The current date and time. | |
| let endDate = Date() | |
| // The date and time 24 hours ago. | |
| let startDate = endDate.addingTimeInterval(-24.0 * 60.0 * 60.0) | |
| // return an array of drinks with a date parameter between | |
| // the start and end dates. | |
| return drinks.filter { (drink) -> Bool in | |
| (startDate.compare(drink.date) != .orderedDescending) && | |
| (endDate.compare(drink.date) != .orderedAscending) | |
| } | |
| } | |
| func removeRows(at offsets: IndexSet) { | |
| numbers.remove(atOffsets: offsets) | |
| } | |
| // Iterate and indexset | |
| indexSet.forEach { islands.remove(at: $0) } | |
| // Filter and Map | |
| private func delete(indexSet: IndexSet) { | |
| let drinkEntries = indexSet | |
| .filter {dm.lastNDrinks[$0].sample != nil } | |
| .map { dm.lastNDrinks[$0].sample! } | |
| dm.deleteSample(samples: drinkEntries) {_,_ in } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment