const sent = 'str str? str! str'; const cens = (str, stop) => { const words = str.split(' '); return words.map(str => stop.includes(str) ? 'replace' : str).join(' ') } console.log(cens(sent, ['str']))