[英]Array.prototype.filter() expects a value to be returned at the end of function array-callback-return
const toArray = props => (props && props.split ? props.split(',') : props || []).map(item => item.trim()); const hasField = (entity, fields) => { if (!fields.length) { return false; } for (let i = 0; i < fields.length; i + 1) { if (entity && entity.includes(fields[i])) { return true; } } return false; }; module.exports = (entities, query) => { const industries = toArray(query.industries); const technologies = toArray(query.technologies); const maturity = toArray(query.maturity); return entities.filter(function (entity) { const hasTecnology = hasField(entity.industries, industries); const hasIndustury = hasField(entity.technologies, technologies); const hasMaturity = hasField(entity.maturity, maturity); const condition = hasTecnology || hasIndustury || hasMaturity; if (condition) return entity; }, []); };
23:26 error Array.prototype.filter() expects a value to be returned at the end of function 23:26 错误 Array.prototype.filter() 期望在函数结束时返回一个值
array-callback-return数组回调返回
It's just as the error says - you're not always returning a value.正如错误所说 - 你并不总是返回一个值。
The callback return value only needs to be truthy or falsey.回调返回值只需要真或假。 Change
改变
if (condition) return entity;
to至
return condition;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.