Вопрос по функции
Добрый день.
Подскажите как сделать такой результат. Исходные данные: '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'])
|
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, время: 17:09. |