我有以下功能,我想删除/重写let comparison变量但仍然使用.reduce. 对使用最新 js 的优雅解决方案有任何想法吗?
const isTargetPresent = (input, target) => {
let comparison = "";
return [...input].reduce((acc, value) => {
comparison += value;
return acc || comparison.indexOf(target) >= 0;
}, false);
};
console.log(isTargetPresent('hello home', 'hello'));
console.log(isTargetPresent('hello banana', 'apple'));