Skip to content

Instantly share code, notes, and snippets.

@rootsec1
Last active June 10, 2019 09:50
Show Gist options
  • Save rootsec1/d132fe60f192cce8001758a856e8dde0 to your computer and use it in GitHub Desktop.
Save rootsec1/d132fe60f192cce8001758a856e8dde0 to your computer and use it in GitHub Desktop.
Cloud function for Fibonacci number check via HTTP triggers.
import * as functions from 'firebase-functions';
exports.pruoo = functions.https.onRequest((request, response) => {
let a:number = 0;
let b:number = 1;
let n = request.query.n;
console.log(request.query);
for(let i:number=2; i<=n; i++) {
const c:number = a+b;
console.log(c);
if(n===c || n===b || n===a) response.status(200).json({ "success": "true" });
else if(c>n) response.status(200).json({ "success": "false" });
a=b;
b=c;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment