0
\$\begingroup\$

This question already has an answer here:

For any String that is composed of lower cased alphabetical characters, make a function that returns a list of all of it's variations, empty strings returns empty list

Test Cases

"" -> []
"a" -> ["a", "A"]
"ab" -> ["ab", "Ab", "aB", "AB"]
"abc" -> ["abc", "Abc", "aBc", "ABc", "abC", "AbC", "aBC", "ABC"]

This is Code-golf. Shortest code in bytes wins

\$\endgroup\$

marked as duplicate by Colera Su, user202729, Toto, Charlie, Arnauld code-golf Dec 12 '17 at 11:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    \$\begingroup\$ Should the output follow a specific order? \$\endgroup\$ – Colera Su Dec 12 '17 at 10:59
  • 4
    \$\begingroup\$ In my opinion, it is much more natural if the empty string "" returns the list [""], because for all other cases, list length = 2 ^ string length. \$\endgroup\$ – user202729 Dec 12 '17 at 11:00
  • \$\begingroup\$ To avoid unclear details in the question (example unclear details: ColeraSu comment above), you can consider leaving your question in the Sandbox for about 24 hours before posting. For now I will temporarily vote to close the question. You may also want to register your profile. \$\endgroup\$ – user202729 Dec 12 '17 at 11:06
  • \$\begingroup\$ Veeeery closely related. (Essentially the same thing, but the input can contain upper-case letters and non-letters.) \$\endgroup\$ – Martin Ender Dec 12 '17 at 11:08
  • \$\begingroup\$ @MartinEnder So should this be closed as a duplicate? Because all answers there can be ported here, and of course very competitive. \$\endgroup\$ – user202729 Dec 12 '17 at 11:13
0
\$\begingroup\$

JavaScript (Firefox 30-57), 75 bytes

f=([c,...s])=>c?[for(t of s[0]?f(s):[''])for(d of c+c.toUpperCase())d+t]:[]

67 bytes if the empty string returns [""]:

f=([c,...s])=>c?[for(t of f(s))for(d of c+c.toUpperCase())d+t]:['']
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.