How to iterate over all the case letters in the zj4zcg5shsz string?

  • 0
    You just need to iterate over all case options
    JavaScript Anonymous, Dec 5, 2019

  • 1 Answers
  • 0
    google paver

    https://stackoverflow.com/a/27995370



    const input = "zj4zcg5shsz";
    const letters = input.split("");
    const permCount = 1 << input.length;
    const result = new Set()

    for (let perm = 0; perm < permCount; perm++) {
    // Update the capitalization depending on the current permutation
    letters.reduce((perm, letter, i) => {
    letters[i] = (perm & 1) ? letter.toUpperCase() : letter.toLowerCase();
    return perm >> 1;
    }, perm);

    result.add(letters.join(""));
    }
    Rose Wong

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!