Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* A "double rakiya number" is an integer that contains a sequence of 2 digits twice (without overlapping).
- For example "23156312" is a "double rakiya number" because it contains "31" twice. Other examples
- of "double rakiya numbers" are: 1212, 3333, 203103, 5210217, 21212121, and 55555. Examples
- of non-"double rakiya numbers" are: 333, 5, 111222, 1234567131, and 12213114.
- Write a JavaScript function that takes as input two numbers (start and end) and prints at the console
- a HTML list holding all numbers in the range [startβ¦end], along with a link to view details about
- all "double-rakiya numbers" in that range. */
- "use strict";
- function printHTMLnumberList(arr) {
- var start = Number(args[0]);
- var end = Number(args[1]);
- function checkRepeatingTwoDigits(number) {
- if (number > 1009) {
- var numStr = number.toString(10);
- for (var i = 0; i + 3 < numStr.length; i += 1) {
- for (var j = i + 2; j + 1 < numStr.length; j += 1) {
- if (numStr[j] == numStr[i] && numStr[j + 1] == numStr[i + 1]) {
- return true;
- }
- }
- }
- }
- return false;
- }
- args[0] = '<ul>';
- var index = 1;
- for (var i = start; i <= end; i += 1) {
- args[index] = "<li><span class=";
- var klass = "'num'>";
- var href = '';
- if (checkRepeatingTwoDigits(i)) {
- klass = "'rakiya'>";
- href = '<a href="view.php?id=' + i + '>View</a>';
- }
- args[index] += klass + i + "</span>" + href + "</li>";
- index++;
- }
- args[index] = "</ul>";
- console.log(args.join('\n'));
- }
- printHTMLnumberList(['5', '8']);
- printHTMLnumberList(['11210', '11215']);
- printHTMLnumberList(['55555', '55560']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement