Because of popular demand, and to avoid disqualifying certain languages, the dictionary can now be provided as input parameter.
Given a dictionary of words, you should write an autocomplete program or function.
"Autocomplete, or word completion, is a feature in which an application predicts the rest of a word a user is typing." (Wikipedia)
Autocompletion is oftenly used to reduce the time needed for typing sentences. After typing a single character, the program will start guessing what the user is trying to say. In this challenge we will simulate the behaviour of autocompleting words.
If the program encounters a word it doesn't know, and no matching autocompletion words can be found, it will assume that the user is trying to type a word the program doesn't know. Good autocompletion software will own and edit a custom dictionary of words, but for the sakes of complexity that's not part of this challenge.
Your program/function will take at least a single parameter of input. This parameter can either be a string or an array of characters, and will consist of lowercase characters
Optionally, your program/function will take a second parameter containing a dictionary of words. More info on this in the paragraph Dictionary.
You should print or return an array of autocompleted words. For each character in the input, an autocompletion should be added to the output array.
The autocompletions will be taken from the provided dictionary. If a word doesn't exist in the dictionary, it will alphabetically search for the next word matching your characters. If no matching word is found, the input will be returned (see test cases)
If you choose to read the dictionary from a file, the file structure should be your list of words, seperated by newlines.
If you choose to submit the dictionary of words as a parameter of a function call, it should be structured as an ordered list of strings;
['cat', 'cake', ...].
The input is always fully lowercase and sorted alphabetically.
alpha calf cave coax code codegimmick codegolf cool gamma
"codegolf" // ["calf", "coax", "code", "code", "codegimmick", "codegolf", "codegolf", "codegolf"] "alpaca" // ["alpha", "alpha", "alpha", "alpa", "alpac", "alpaca"] ["t", "h", "i", "s"] // ["t", "th", "thi", "this"] ("catses", ["cake","cats"]) // ["cake", "cake", "cats", "cats", "catse", "catses"]
This is code-golf, shortest code in bytes wins