DEV Community

Rajiv Chaulagain
Rajiv Chaulagain

Posted on

4

Let's print fibonacci series with js with all explanation and problem solving.

Here, Problem solving is the only skill a programmer needs so I would like to show some case for it.
In above question we can find that we have to print fibonacci series,

Now fibonacci series looks like this :
1 , 1, 2 , 3 , 5 , 8 ......

Now, we have to print this fibonacci series so first thing we need is the pattern here , we find that the first number and second number while adding gives the third number.
For eg : 1 + 1 -> 2 , 1 + 2 -> 3 , 2 + 3 -> 5 .

woo we found the pattern half of the solution is done. Try solving this problem into some paper before writing on code.
Then start coding immediately

let a = 0;
let b = 1;
let c;
for (let index = 0; index < 10; index++) {
    console.log(b);
    c = a + b
    a = b 
    b = c
}
Enter fullscreen mode Exit fullscreen mode

Now what we have done .
1 -> Declaring variable a , b ,c
2 -> looping so that we can get how much interval or value we want
3 -> logging the first value as b that gives 1.
4 -> Now variable c adds two variable 1 and 0 in initial
5 -> a takes value of b and b takes value of c

Conclusion,
Hence this is about the problem solving not about coding

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free