Skip to content

Instantly share code, notes, and snippets.

@rzkhosroshahi
Created July 21, 2017 23:02
Show Gist options
  • Save rzkhosroshahi/236b362a8c665c83dc9570abbaf7a48a to your computer and use it in GitHub Desktop.
Save rzkhosroshahi/236b362a8c665c83dc9570abbaf7a48a to your computer and use it in GitHub Desktop.
This snippet computing the golden ratio field.
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