- An array containing three integers:
2in any order (i.e.
[2, 0, 1])
- And a string of length >= 2 only containing alphabetic letters (both lower- and uppercase) and digits (i.e.
Based on the array we sort and output the string.
How does this work?
- The array indicates the order precedence of
0-9, the first being
0; second being
1; and third being
- The individual characters of the string can then be ordered based on that.
[2, 0, 1]
Based on the array, we know our order precedence is
Based on that, we can convert and output the string:
- For the array you can choose to use 0-indexed or 1-indexed input, so
[3, 1, 2]is also a valid input if you prefer to use 1-indexed arrays.
- The string (both input and output) only contains valid characters:
- If your language doesn't support arrays (or if you choose to), you are free to use strings instead of arrays for the first parameter (i.e.
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
- Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
[2, 0, 1] & a1B2c3 -> 123acB [2, 1, 0] & aAaA909UuHWw9gh2 -> 02999AAHUWaaghuw [2, 1, 0] & 6Bx43 -> 346Bx [1, 0, 2] & jfjf33g -> ffgjj33 [0, 2, 1] & AbC13 -> b13AC [1, 2, 0] & Qfl0l -> Q0fll [0, 1, 2] & 9870abcABC -> abcABC0789 [0, 2, 1] & test123 -> estt123 [2, 0, 1] & WHAT -> AHTW [2, 0, 1] & WhAt -> htAW [1, 0, 2] & 102BACbac -> ABCabc012