-2

Can anybody help me out with creating a script that would calculate all possible combinations of text that is displayed inside a input box?

let's say that we have 12 in the input box. Script reads it, calculates, and prints that this input has 4 possible variations (11, 12, 21, 22).

How can I achieve this?

Andy Andy
  • 279
  • 4
  • 7
  • 17
  • 1
    A simple google search would point you in the right direction. EG http://stackoverflow.com/questions/5232295/is-there-any-pre-built-method-for-finding-all-permutations-of-a-given-string-in – Kevin Lynch Sep 07 '14 at 18:23

1 Answers1

2

You first read the input, its probably a string, then you want to split it into an array. So you get every possible digit in a new array of possible inputs then you traverse this array, using recursion, and adding the character on that index of the array to a possible result, and telling the function how deep you want to go (the original input length), and when you reach your length, you print it and go 1 step back on the recursion. That's more of a programming question than jQuery, there might be some method on jQuery that makes it easier to solve, but your problem here is more about the logic.

iagowp
  • 2,428
  • 1
  • 21
  • 32