DEV Community

katongole Isaac
katongole Isaac

Posted on

Introduction to JavaScript

Now we jumpin to new style of coding easily,fast and awesome stuffs. I know most companies and big organization are in the transition to adopt what's trending, fast and secure. Well i may weird by now ! but after this, you would wish to stay for more blogs like this.
Even when you are new to the world of codes, you still have a big opportunity to understand what's going. Hey!!!, i forgot to tell this, am from testing Google's fastest engine, i don't mean a car engine NO, guess what, its V8.
i created a function that takes one argument (of type int) and returns a fibonacci number in that index forexample

fibonacci(5);
Enter fullscreen mode Exit fullscreen mode

it does the count from 1,2,3,5,8 and returns 8 because is in position 5. It returned it in 0 seconds.
Now here is the crazy thing i did,

   fibonacci(1000000000);
Enter fullscreen mode Exit fullscreen mode

It thought Google's V8 will spend some good times to complete the task, but i was surprised when i returned the result (Infinity) in just 1.614 minutes. Yet i wrote the very code in Python but i only heard heat from my laptop, fans doubles the noise, it took Python over 10 minutes without returning the results till it cancelled the action.
Well don't mind more to the above boring story, the good news are JS,
and in full in Just Stupid, Ooohh Ooooh nooo !!! its JavaScript

Top comments (1)

Collapse
 
katongole_isaac profile image
katongole Isaac • Edited

Thanks so much, I finally understood it. check

function* fibonacci(number = 1n){
  let first = 1n;
  let second = 1n;
  let next = 1n;
  for(let count = 1n; count <= number; count++){
    yield next;
    first = second;
    second = next;
    next = first + second;
  }
}
let gen = fibonacci(2n); 
console.log(gen.next());//{ value: 1n, done: false }
console.log(gen.next());//{ value: 2n, done: false }
console.log(gen.next());//{ value: undefined, done: false }
Enter fullscreen mode Exit fullscreen mode