Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- const maxLength = 10;
- const indeces = [0];
- while (indeces.length < maxLength) {
- let string = ""
- for (let i = 0; i < indeces.length; i++) {
- string += chars[indeces[i]]
- }
- console.log(string);
- let lastElementIndex = indeces.length - 1;
- increase(lastElementIndex);
- function increase (index) {
- //Room to increase
- if (indeces[index] < chars.length - 1)
- indeces[index]++;
- //No room to increase, increase element before last
- else {
- //overflow it
- indeces[index] = 0;
- //Already at start, add new character
- if (index == 0)
- indeces.unshift(0);
- //Otherwise increase character before index
- else increase(index-1)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement