Created
July 21, 2017 23:02
-
-
Save rzkhosroshahi/236b362a8c665c83dc9570abbaf7a48a to your computer and use it in GitHub Desktop.
This snippet computing the golden ratio field.
This file contains 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
function scale(n){ | |
if(n === 0) return 1; | |
if(n === 1) return 1.618; | |
if(n === -1) return 0.618; | |
if(n > 0){ | |
return scale(n-1) + scale(n-2); | |
} | |
if(n < 0){ | |
return scale(n+2) - scale(n+1); | |
} | |
} | |
console.log(scale(0)); // 1 | |
console.log(scale(1)); // 1.618 | |
console.log(scale(4)); // 6.854 | |
console.log(scale(-1)); // 0.618 | |
console.log(scale(-2)); // 0.382 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment