Advertisement
adriyanbulgary

Exam 28.08 - 01.DoubleRakiyaNumbers

Aug 2nd, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     var start = parseInt(input[0]);
  3.     var end = parseInt(input[1]);
  4.     var notBeer = "<li><span class='num'>NUMBER</span></li>\n";
  5.     var beer = "<li><span class='rakiya'>NUMBER</span><a href=\"view.php?id=NUMBER>View</a></li>\n";
  6.     var output = '<ul>\n';
  7.     var isBeer = false;
  8.     for(var a = start; a <= end; a++) {
  9.         var number = String(a);
  10.         var num = number;
  11.         for(var b = 0; b < number.length; b++) {
  12.             var digits = number[b] + number[b+1];
  13.             if(num.split(digits).length - 1 > 1 ) {
  14.                 // console.log("There is a beer - " + digits );
  15.                 isBeer = true;
  16.             }
  17.         }  
  18.             if(isBeer) {
  19.                 isBeer = false;
  20.                 var addNumber = beer.replace(/NUMBER/g,number);
  21.                 output +=addNumber;
  22.             } else {
  23.                 var addNumber = notBeer.replace("NUMBER",number);
  24.                 output += addNumber;
  25.             }  
  26.     }
  27.     output += "</ul>";
  28.     console.log(output);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement