0

I want to create a loop to create all numbers in a given number. Given number 123 I want to get

123
132
213
231
312
321


array = array.map(function(i,v) {
    results.push(i);
  })

This is what i am using now and still working on it but it fails

tried

results = array.sort(function(a, b) {
    return a - b;
  });

This one also fail.

Martin
  • 365
  • 4
  • 7
  • 22
  • what is the expected output of 112 ? – marvel308 Sep 18 '17 at 10:56
  • you are looking for permutation (different ordering of given items). just mapping does not work, because you need to take one item out of the rest. – Nina Scholz Sep 18 '17 at 10:56
  • @NinaScholz im looking also in loop but i am still working on it.. am looking on all solution.. looking at array as long as i get he result – Martin Sep 18 '17 at 10:57
  • @marvel308 duplicated number should be there combine the digit to get all possible 3 digit number so 112 121 211 i guess – Martin Sep 18 '17 at 10:58

0 Answers0