As a conlanger, I am interested in creating a uniform, naturalistic language. One of the tricks is to create vocabulary according to certain structures of words. An example from English: In English, we have the word “tap” structured consonant-vowel-consonant. Usually, this means that there are many other words of this structure: “cat”, “dog”, “rock”, “fog”, “good”, etc.
As input, you have:
- an array
Ccontaining strings: consonants (
Cis the first letter in the word consonants). Identical consonants cannot be repeated on this list. For example, this list cannot contain ['b', 'b'].
- an array
Vcontaining strings: vowels (
Vis the first letter of the word vowels). Identical vowels cannot be repeated on this list.
S, which contains something like this "CVCCV" (any combination of "C" and "V")
Your task is to replace “C” in the string with a randomly taken string from array
C and replace “V” in the string with a randomly taken string from array
V and return (or display) this string.
"randomly" is defined as all possibilities having an equal chance of being selected. This is a kind of simplification: in real languages as well as in conlangs, there are very frequent (for example 'r' in English) and not very frequent sounds but this is just a code-golf.
This is code-golf so the lowest byte count wins.
Input: C = ['p', 'b', 't', 'd', 'k', 'g', 'm', 'n', 'w'] V = ['a', 'o', 'u', 'i', 'e', 'ä'] S = 'CVCCV' Output: pakto
Input: C = ['p', 'b', 't', 'd', 'k', 'g', 'v', 's', 'r'] V = ['a', 'o', 'u', 'i', 'e', 'ä', 'ᵫ'] S = 'CVVCCVCCV' Output: koebrᵫvtä