0
votes

Let's say, in the string "91910500", there are numbers (00, 10, 19, 50, 91, 105, 500, 919, 9191, 1910, 1050, 10500, etc...).

You have a range number from 0000000001 to 99999999999. And you have to find a string which contains all the numbers from that range. whatever you guess a number from that range, you will find that number in the main string.

What will be the main string for that range? With the following the code, I still see duplicate in main key.

var s = "";

for (i = 0; i < 100; i++) {
  console.log('Searching the number ' + i);
  d = i.toString;

  if (s.indexOf(d) >= 0) {} else {
    s = s.concat(i);
  }

  console.log('Key is \n' + s);
}
1
Welcome to Stack Overflow! Check how to create How to create a Minimal, Complete, and Verifiable example so that you can get a much better response to your question.n4m31ess_c0d3r
@n4m31ess_c0d3r yes, I add the code for it.Keyme

1 Answers

0
votes

Your code is almost correct, you just need to update 2 lines:

for (i = 0; i < 100; i++) {

to:

for (i = 100 - 1; i >= 0; i--){

And:

d = i.toString;

to:

d = i.toString();