Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  2. const maxLength = 10;
  3.  
  4. const indeces = [0];
  5.  
  6. while (indeces.length < maxLength) {
  7.  
  8. let string = ""
  9. for (let i = 0; i < indeces.length; i++) {
  10. string += chars[indeces[i]]
  11. }
  12. console.log(string);
  13.  
  14. let lastElementIndex = indeces.length - 1;
  15.  
  16. increase(lastElementIndex);
  17.  
  18. function increase (index) {
  19.  
  20. //Room to increase
  21. if (indeces[index] < chars.length - 1)
  22. indeces[index]++;
  23.  
  24. //No room to increase, increase element before last
  25. else {
  26.  
  27. //overflow it
  28. indeces[index] = 0;
  29.  
  30. //Already at start, add new character
  31. if (index == 0)
  32. indeces.unshift(0);
  33.  
  34. //Otherwise increase character before index
  35. else increase(index-1)
  36. }
  37.  
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement