Skip to content

Instantly share code, notes, and snippets.

@arashkashi
Last active July 27, 2016 12:08
Show Gist options
  • Save arashkashi/62a6f047fad51e0b76cd80e632231664 to your computer and use it in GitHub Desktop.
Save arashkashi/62a6f047fad51e0b76cd80e632231664 to your computer and use it in GitHub Desktop.
maps a range of input to a range of output
import Cocoa
var str = "Hello, playground"
typealias LinearEquation = Double -> Double
func getLinearEquation(inp: (min: Double, max: Double),
out: (min: Double, max: Double)) -> LinearEquation {
let m = (out.max - out.min) / (inp.max - inp.min)
let b = out.max - m * inp.max
return {
$0 * m + b
}
}
let linearmap = getLinearEquation((3, 5), out: (20, 60))
linearmap(3)
linearmap(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment