簡體   English   中英

Array.prototype.filter() 期望在函數 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() 期望在函數結束時返回一個值
數組回調返回


  • 第 23:26 行是 ==> module.exports = (entities, query) => {
  • 你能檢查一下嗎? 我在這里做錯了什么?

正如錯誤所說 - 你並不總是返回一個值。

回調返回值只需要真或假。 改變

if (condition) return entity;

return condition;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM