Inspired by this unassuming StackOverflow question.
The idea is simple; given a String and an array of Strings, remove any instances of words in the array (ignoring case) from the input String other than the first, along with any additional whitespace this may leave. The words must match entire words in the input String, and not parts of words.
e.g. "A cat called matt sat on a mat and wore a hat A cat called matt sat on a mat and wore a hat", ["cat", "mat"]
should output "A cat called matt sat on a mat and wore a hat A called matt sat on a and wore a hat"
Input
- Input can be taken as either a String, and an array of Strings or an array of Strings where the input String is the first element. These parameters can be in either order.
- The input String may not be taken as a list of space-delimited Strings.
- The input String will have no leading, trailing or consecutive spaces.
- All input will only contain characters [A-Za-z0-9] with the exception of the input String also including spaces.
- The input array may be empty or contain words not in the input String.
Output
- The output can either be the return value from a function, or printed to STDOUT
- The output must be in the same case as the original String
Test cases
the blue frog lived in a blue house, [blue] -> the blue frog lived in a house
he liked to read but was filled with dread wherever he would tread while he read, [read] -> he liked to read but was filled with dread wherever he would tread while he
this sentence has no matches, [ten, cheese] -> this sentence has no matches
this one will also stay intact, [] -> this one will also stay intact
All the faith he had had had had no effect on the outcome of his life, [had] -> All the faith he had no effect on the outcome of his life
5 times 5 is 25, [5, 6] -> 5 times is 25
Case for different case, [case] -> Case for different
the letters in the array are in a different case, [In] -> the letters in the array are a different case
This is a test Will this be correct Both will be removed, [this,will] -> This is a test Will be correct Both be removed
As this is code golf, lowest byte count wins!