Skip to content

Instantly share code, notes, and snippets.

@rootsec1
Last active June 10, 2019 08:19
Show Gist options
  • Save rootsec1/cbb03fc0fb20b756673c975d513fe009 to your computer and use it in GitHub Desktop.
Save rootsec1/cbb03fc0fb20b756673c975d513fe009 to your computer and use it in GitHub Desktop.
Check if number belongs to Fibonacci Sequence using Typescript
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;
}
@rootsec1
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment