Skip to content

Instantly share code, notes, and snippets.

@heestand-xyz
Created October 15, 2018 11:47
Show Gist options
  • Save heestand-xyz/adeceea19c9f57a97fe6d68367966db2 to your computer and use it in GitHub Desktop.
Save heestand-xyz/adeceea19c9f57a97fe6d68367966db2 to your computer and use it in GitHub Desktop.
Filter
var filters: [String: [CGFloat]] = [:]
func filter(_ val: CGFloat, for count: Int, as id: String) -> CGFloat {
if var filter = filters[id] {
filter.insert(val, at: 0)
let lastVal: CGFloat
if filter.count > count {
lastVal = filter.popLast()!
} else {
lastVal = filter.last!
}
filters[nameID] = filter
return lastVal
} else {
filters[id] = [val]
return val
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment