Stolen from @Downgoat with permission
The point of this challenge is to (not) settle the debate on the pronunciation of "gif".
The pronunciation of gif is debated and while it's supposed to be (and should be) pronounced jif, it's still commonly disputed.
In this challenge you will be given a set of words that have a g or j, representing the sound that the word is pronounced with. You'll also get some text in which you have to fix the incorrect spellings of gif.
Because this is the internet and everyone always wrong. It's (not) common courtesy to correct them.
An example of a wrong pronunciation would be:
There was a gif of a mouse eating a burrito
The wrong spelling of gif? Unacceptable! This must be corrected immediately:
There was a jif (as in jar) of a mouse eating a burrito
Are we done? Nope, you're still wrong.
You're always wrong
This must work the other way:
In the jif the cat wore a hat of a cat
This obvious misspelling must be fixed, we shall correct this to:
In the gif (as in graphic) the cat wore a hat of a cat
Rules
- Input is a string (the sentence) and an array of strings (or any reasonable alternative, such as a comma separated string) in any order
- You may take the
g
andj
words in any order. They may be taken separately. - Every instance of
gif
(any case) in the sentence must be replaced withjif (as in ___)
where___
is a uniformly random selected word beginning withj
from the array of strings, and vice versa forjif
with words beginning withg
. - ONLY the words
gif
andjif
should be replaced (i.e "jiffy" should not be changed). Those words have done no wrong. - You are guaranteed that at least one word in the array begins with
g
and at least one begins withj
. - Case must be preserved (e.g.
GiF
->JiF
). - You may write a program or a function
- Standard loopholes apply
- We need to (not) settle the debate quickly; shortest code in bytes wins
Examples
Input and output separated by a single line:
graphic, jar, jam, gram
I saw a jif of how to pronounce gif that showed gif is pronounced jif
I saw a gif (as in graphic) of how to pronounce jif (as in jar) that showed jif (as in jam) is pronounced gif (as in gram)
gravy, jeff
G is for gIf, h is for JiF, i is for gIF, j is for JIf
G is for jIf (as in jeff), h is for GiF (as in gravy), i is for jIF (as in jeff), j is for JIf (as in gravy)
joke, june, gorilla, great
Jiffy should not be treated as a GIF or JIF, like gifted.
Jiffy should not be treated as a JIF (as in june) or GIF (as in great), like gifted.
The pronunciation of gif is debated and while it's supposed to be (and should be) pronounced **gif,** it's still commonly disputed.
FTFY ;) \$\endgroup\$