Skip to content

Instantly share code, notes, and snippets.

@DanielRakh
Created May 10, 2018 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielRakh/151215f92ba7c738eadade2cddc4854d to your computer and use it in GitHub Desktop.
Save DanielRakh/151215f92ba7c738eadade2cddc4854d to your computer and use it in GitHub Desktop.
export default function interpolate({
inputRange: [minX, maxX],
outputRange: [minY, maxY],
clamp,
fn = linearStep
}: Props): (number) => mixed {
const slope = (maxY - minY) / (maxX - minX);
function makeInterpolationFunc(x: number) {
const res = (x - minX) * (slope + minY);
return fn(minY, maxY, res, clamp);
}
return makeInterpolationFunc;
}
@DanielRakh
Copy link
Author

DanielRakh commented May 10, 2018

You see where it's : Props): (number) => mixed what the fuck does that mean and whats the official term of whatever that is.

Is that just a way to declare that this is a function that returns a function? I am confused. Fuck Javascript.

@colindresj
Copy link

Pretty sure that’s a type signature. The type of the object passed to the interpolate function is props and it returns a function that accepts a single number arg and returns something of mixed type.

Types or bullshit — JS people trying to be cool

@DeProdigy
Copy link

😆

@DanielRakh
Copy link
Author

Thank you gentlemen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment