Created
July 31, 2014 10:14
-
-
Save dessso/d9ec16a9d3b545f04c72 to your computer and use it in GitHub Desktop.
exam 28.07.2014 JavaScript first problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solve(input) { | |
var first = Number(input[0]); | |
var second = Number(input[1]); | |
console.log('<ul>'); | |
var together = []; | |
for (var i = first; i <= second; i++) { | |
together.push(i); | |
} | |
for (var j = 0; j < together.length; j++){ | |
var currentNumber = together[j].toString(); | |
var currentNumAsArray = currentNumber.split(''); | |
var firstDouble = currentNumAsArray[0] + currentNumAsArray[1]; | |
if (currentNumber.indexOf(firstDouble, 2) !== -1) { | |
console.log("<li><span class='rakiya'>" + currentNumber + "</span><a href=" + '"' + "view.php?id=" + currentNumber + ">View</a></li>"); | |
} | |
else { | |
var secondDouble = currentNumAsArray[1] + currentNumAsArray[2]; | |
if (currentNumber.indexOf(secondDouble, 3) !== -1) { | |
console.log("<li><span class='rakiya'>" + currentNumber + "</span><a href=" + '"' + "view.php?id=" + currentNumber + ">View</a></li>"); | |
} | |
else { | |
var thirdDouble = currentNumAsArray[2] + currentNumAsArray[3]; | |
if (currentNumber.indexOf(thirdDouble, 4) !== -1) { | |
console.log("<li><span class='rakiya'>" + currentNumber + "</span><a href=" + '"' + "view.php?id=" + currentNumber + ">View</a></li>"); | |
} | |
else { | |
var fourthDouble = currentNumAsArray[3] + currentNumAsArray[4]; | |
if (currentNumber.indexOf(fourthDouble, 5) !== -1) { | |
console.log("<li><span class='rakiya'>" + currentNumber + "</span><a href=" + '"' + "view.php?id=" + currentNumber + ">View</a></li>"); | |
} | |
else { | |
var fifthDouble = currentNumAsArray[4] + currentNumAsArray[5]; | |
if (currentNumber.indexOf(fifthDouble, 6) !== -1) { | |
console.log("<li><span class='rakiya'>" + currentNumber + "</span><a href=" + '"' + "view.php?id=" + currentNumber + ">View</a></li>"); | |
} | |
else { | |
var sixthDouble = currentNumAsArray[5] + currentNumAsArray[6]; | |
if (currentNumber.indexOf(sixthDouble, 7) !== -1) { | |
console.log("<li><span class='rakiya'>" + currentNumber + "</span><a href=" + '"' + "view.php?id=" + currentNumber + ">View</a></li>"); | |
} | |
else { | |
console.log("<li><span class='num'>" + currentNumber + "</span></li>"); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
console.log('</ul>'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment