Just launched! Get 30% off Rails Revisited Have a Look

Buy or Subscribe

You can access this course in just a minute, and support my efforts to rid the world of crappy online courses!

Buy Standalone  Subscribe

No, this video is not about Ruby, Python, JavaScript, etc. Dynamic programming is a way to solve a problem using an algorithm in a fairly prescribed way. It sounds complicated, but itā€™s anything but.

Dynamic programming gives us a way to elegantly create algorithms for various problems and can greatly improve the way you solve problems in your daily work. It can also help you ace an interview.

You knew Fibonacci was going to come up in this book at some point didnā€™t you! Well, here it is. Iā€™m using it here because itā€™s the simplest way to convey the dynamic programming process. Also: you will be asked how to solve Fibonacci at some point in your career, and youā€™re about to get three different approaches!

Which leads right to a great opening point: our jobs are about solving problems. When you go to these interviews, they mostly want to see how you would go about solving something complex. As it turns out, the Interviewing For Dummies book says that Fibonacci is a great question for just that case.

The Code

//Fibonacci with Dynamic Programming
const calculateFibAt = (n) =>{
  var memoTable = [0,1];
  for(var i=2;i<=n;i++){
    memoTable.push(memoTable[i-2] + memoTable[i-1])
  }
  return memoTable;
};
console.log(calculateFibAt(1000));


//slow, recursive way
const fibSlow = n => n < 2 ? n : fibSlow(n-2) + fibSlow(n-1);

console.log(fibSlow(10));