merge: Optimize the space complexity of the fibonacci algo (#899)

* docs: update js doc

* feat: add number type validation condition

* pref: Optimize space complexity

remove the Array from the algo and used two flag varible to calculate last two numbers & optimize the sapce complexity O(n) to O(1)

* test: add test case for invalid types
This commit is contained in:
Fahim Faisaal
2022-02-22 16:50:46 +06:00
committed by GitHub
parent 743b3179f7
commit 8bf29fe17c
2 changed files with 23 additions and 9 deletions

View File

@ -1,6 +1,12 @@
import { fibonacci } from '../FibonacciNumber'
describe('FibonacciNumber', () => {
describe('Testing FibonacciNumber', () => {
it('Testing for invalid type', () => {
expect(() => fibonacci('0')).toThrowError()
expect(() => fibonacci('12')).toThrowError()
expect(() => fibonacci(true)).toThrowError()
})
it('fibonacci of 0', () => {
expect(fibonacci(0)).toBe(0)
})