Ispirato a questa domanda StackOverflow senza pretese .
L'idea è semplice; data una stringa e un array di stringhe, rimuovi qualsiasi istanza di parole nell'array (ignorando il caso) dall'input String diverso dal primo, insieme a qualsiasi altro spazio bianco che può lasciare. Le parole devono corrispondere a parole intere nella stringa di input e non a parti di parole.
ad es. "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"]dovrebbe produrre"A cat called matt sat on a mat and wore a hat A called matt sat on a and wore a hat"
Ingresso
- L'input può essere preso come una stringa e una matrice di stringhe o una matrice di stringhe in cui la stringa di input è il primo elemento. Questi parametri possono essere in entrambi gli ordini.
- La stringa di input non può essere considerata come un elenco di stringhe delimitate da spazi.
- La stringa di input non avrà spazi iniziali, finali o consecutivi.
- Tutti gli input conterranno solo caratteri [A-Za-z0-9] con l'eccezione della stringa di input che include anche spazi.
- La matrice di input può essere vuota o contenere parole non presenti nella stringa di input.
Produzione
- L'output può essere il valore restituito da una funzione o stampato su STDOUT
- L'output deve essere nello stesso caso della stringa originale
Casi test
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
Dato che si tratta di code golf, vince il conteggio di byte più basso!
This is a test Will this be correct Both will be removed+this will. Le seconde due parole vengono rimosse correttamente, ma per qualche motivo rimosse anchebela seconda dopowill.