Skip to content

Instantly share code, notes, and snippets.

@mckamey
Forked from 140bytes/LICENSE.txt
Created May 18, 2011 22:17
Show Gist options
  • Save mckamey/979716 to your computer and use it in GitHub Desktop.
Save mckamey/979716 to your computer and use it in GitHub Desktop.
Fibonacci
/**
* A tweet-sized, Fibonacci sequence generator.
*
* @param {number} n index within the sequence
* @return {number} Fibonacci value corresponding to the index
*/
function(n) {
for (var a = 0, b = 1, i = 2; i <= n;) {
(i++ % 2) ? b += a : a += b;
}
return (n % 2) ? b : a;
}
function(n){for(var a=0,b=1,i=2;i<=n;)i++%2?b+=a:a+=b;return n%2?b:a}
Copyright (c) 2011 Stephen M. McKamey, http://mck.me
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "fib_tweet",
"description": "A tweet-sized, Fibonacci sequence generator.",
"keywords": [
"Fibonacci",
"fib",
"tweet"
]
}
@p01
Copy link

p01 commented May 29, 2011

@wrayal: Indeed. Crazy busy. o_O Do you have a link to one of Jed's 140byt.es gists using a named function?

@wrayal
Copy link

wrayal commented May 29, 2011

@p01: I thought I had a better example where it wasn't picked up in the comments, but the only one I could see immediately was this: https://gist.github.com/962814

@p01
Copy link

p01 commented May 29, 2011

Thanks for sharing. The argument is sound. I relayed it to the master/parent gist.

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