Memoization What is Memoization? Memoization is a technique used in programming to write optimizied code. This is very useful in use cases when the system is performing very CPU intensive tasks repeatedly. What are the use Cases for Memoization? Memoization can be useful when the system is performing same task again and again like API output caching - This is not recommended though as it requires a cache invalidation mechanism which is tricky to implement. Calling a recursive function e.g. Fibonacci series. One thing to note here is, memoization works well in case of pure function only. What is a Pure function ? A function which produces the same output for the same given input every time. Lets understand this with the Fibonacci series example. Below program is written without memoization where result of previously executed function is not cached. So each time the program calls the Fibonacci function, it calculates results every time. Now, below is the improved memoized version o
Array Extensions Library- Unit Test This post is second in series of creating Array Extension Library In this post we will learn how we can add unit test cases to our library. We will use Jasmine framework to Unit test our library. For that, use below command. >> npm install jasmine As we have developed our library in typescript, it will convenient to add typing for Jasmine as well. To install typing for Jasmine. Use below command. >> npm uninstall @types/jasmine After running these commands, our package.config will look like Now, we will add new file named extension.spec.ts under test directory. In this file we will import extension library first. We will now define one class named Heros, Which we use to create Array and test all our extension methods against it. Now we will describe our test suite using describe function provided by Jasmine. And initialize arrays with our primitive and custom type(Heros) in beforeEach function provided by jasmine. Now, we will