Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Вопрос по функции (https://javascript.ru/forum/misc/80839-vopros-po-funkcii.html)

AleBa 12.08.2020 14:39

Вопрос по функции
 
Добрый день.

Подскажите как сделать такой результат. Исходные данные: 'str str? str! str'.
Нужно: 'replace str? str! replace '.

const sent = 'str str? str! str';

const cens = (str, stop) => {
 
  const words = str.split(' ');
  
  
  for (const item of words) {
    if () {
      
    }

  }
    return words.join(' ')
}


  

cens(sent, ['str'])

рони 12.08.2020 14:44

AleBa,
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']))


Часовой пояс GMT +3, время: 14:23.