Last active
June 10, 2019 08:19
-
-
Save rootsec1/cbb03fc0fb20b756673c975d513fe009 to your computer and use it in GitHub Desktop.
Check if number belongs to Fibonacci Sequence using Typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkIfNumberIsFibonacci(n:number):boolean { | |
let a:number = 0; | |
let b:number = 1; | |
for(let i:number=2; i<=n; i++) { | |
const c:number = a+b; | |
if(n===c || n===b || n===a) return true; | |
a=b; | |
b=c; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Pruoo Care. This is the response for Q1B.
I know this could have been done in a much more efficient way but I hope this suffices since it's just a test.