Guest User

Untitled

a guest
Nov 13th, 2014
170
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function buildATable(input) {
  2.     var start = parseInt(input[0]);
  3.     var end = parseInt(input[1]);
  4.  
  5.     var fib = [];
  6.     fib[0] = 0;
  7.     fib[1] = 1;
  8.     for(var i = 2; i < 36; i++) {
  9.         fib[i] = fib[i - 2] + fib[i - 1];
  10.     }
  11.  
  12.     function isFibonacci(number) {
  13.         var count = 0;
  14.  
  15.         for(var i = 0; i < 36; i++) {
  16.             if(fib[i] == number)
  17.                 count++;
  18.         }
  19.  
  20.         if(count == 1)
  21.             return 'yes';
  22.         else
  23.             return 'no';
  24.     }
  25.     console.log('<table>\n<tr><th>Num</th><th>Square</th><th>Fib</th></tr>');
  26.  
  27.     for(var num = start; num <= end; num++) {
  28.         console.log('<tr><td>' + num + '</td><td>' + num * num + '</td><td>' + isFibonacci(num) + '</td></tr>');
  29.     }
  30.     console.log('</table>');
  31. }
RAW Paste Data