Closed Bug 1226545 Opened 10 years ago Closed 10 years ago

fibonacci series example is incorrect

Categories

(Developer Documentation Graveyard :: JavaScript, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: amit17thawait, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36 Steps to reproduce: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators#Advanced_generators The fibonacci generator implementation is incorrect. Actual results: The actual result of the solution given for fibonacci generates sequence as : 1, 1, 2, 3, 5, 8, 13, 21, ... Expected results: The actual fibonacci sequence starts from 0 but not 1. Its even stated incorrectly in the wikipedia. The first number for fibonacci series start with 0 and not 1. You can contact any mathematics scientist and they will also say it starts with 0 and not 1. The correct solution should be : function* fibonacci(){ var fn1 = 0; var fn2 = 1; while (true){ var current = fn1; fn1 = fn2; fn2 = current + fn1; var reset = yield current; if (reset){ fn1 = 0; fn2 = 1; } } } Please refer these links for reference : 1) https://www.quora.com/Does-the-Fibonacci-sequence-start-with-0 2) http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fib.html 3) http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibtable.html
Component: General → JavaScript
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.