Created
October 15, 2018 11:47
-
-
Save heestand-xyz/adeceea19c9f57a97fe6d68367966db2 to your computer and use it in GitHub Desktop.
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
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