![](/img/trans.png)
[英]Array.prototype.filter() expects a value to be returned at the end of arrow function array-callback-return
[英]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 錯誤 Array.prototype.filter() 期望在函數結束時返回一個值
數組回調返回
正如錯誤所說 - 你並不總是返回一個值。
回調返回值只需要真或假。 改變
if (condition) return entity;
至
return condition;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.