Tab completion is a useful feature that auto-completes partially written commands. You're going to be implementing it.
For example, if the available commands were
['apply','apple','apple pie','eat'], then
a would complete to
appl, as all of the commands that start with
a also start with
You need to input a string, A, and a set of strings, B.
You need to output the longest common prefix of all B that starts with A.
- If none of the options starts with A, then return A
- You can assume that B is nonempty, and that all strings are nonempty
- You cannot assume that any of the options start with A, nor that the common prefix will be longer than A
- You can be case sensitive or case insensitive.
- You only need to handle printable ASCII
- Built-ins that explicitly do this task are allowed
'a' ['apply','apple','apple pie','eat'] => 'appl' 'a' ['apple pie'] => 'apple pie' 'apple' ['eat','dine'] => 'apple' 'program' ['programa','programb'] => 'program' '*%a(' ['*%a()-T>','*%a()-T<','@Da^n&'] => '*%a()-T' 'a' ['abs','absolute','answer'] => 'a' 'a' ['a','abs'] => 'a' 'one to' ['one to one','one to many'] => 'one to '
Note the trailing space on the last test case
This is a code-golf, so make your answers as short as possible!