Advertisement
Guest User

Untitled

a guest
Mar 12th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. function Solve(arr) {
  2. var start = arr[0];
  3. var end = arr[1];
  4.  
  5. function isFib(val) {
  6. var prev = 0;
  7. var curr = 1;
  8. while (prev <= val) {
  9. if (prev === val) {
  10. return true;
  11. }
  12. curr = prev + curr;
  13. prev = curr - prev;
  14. }
  15. }
  16.  
  17. var result = "<table>\n<tr><th>Num</th><th>Square</th><th>Fib</th></tr>\n";
  18. for (var i = start; i <= end; i++) {
  19. if (isFib(i) === true) {
  20. result += "<tr><td>" + i + "</td><td>" + Math.pow(i, 2) + "</td><td>" + "yes" + "</td></tr>\n";
  21. } else {
  22. result += "<tr><td>" + i + "</td><td>" + Math.pow(i, 2) + "</td><td>" + "no" + "</td></tr>\n";
  23. }
  24. }
  25. result += "</table>";
  26. //console.log(result);
  27. return result;
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement