简体   繁体   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; }, []); };

  • output showing:输出显示:

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数组回调返回


  • Line 23:26 is ==> module.exports = (entities, query) => {第 23:26 行是 ==> module.exports = (entities, query) => {
  • Could you please check this?你能检查一下吗? What I wrongly doing here?我在这里做错了什么?

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.

相关问题 Array.prototype.filter() 期望在箭头函数 array-callback-return 结束时返回一个值 - Array.prototype.filter() expects a value to be returned at the end of arrow function array-callback-return Array.prototype.filter() 期望在箭头函数的末尾返回一个值 - Array.prototype.filter() expects a value to be returned at the end of arrow function 我返回 `boolean` 但 Array.prototype.filter() 期望在箭头 function 的末尾返回一个值 - i return `boolean` but Array.prototype.filter() expects a value to be returned at the end of arrow function react js Array.prototype.filter() 期望在箭头结束时返回一个值 function - react js Array.prototype.filter() expects a value to be returned at the end of arrow function Array.prototype.map() 期望来自箭头的返回值 function array-callback-return - Array.prototype.map() expects a return value from arrow function array-callback-return 如何解决这个警告警告 Array.prototype.map() 期望从箭头函数数组回调返回的返回值? - How fix this warrning warning Array.prototype.map() expects a return value from arrow function array-callback-return? 预期在箭头函数结束时返回一个值:array-callback-return - Expected to return a value at the end of arrow function: array-callback-return 预期在箭头函数array-callback-return的末尾返回一个值 - Expected to return a value at the end of arrow function array-callback-return 期望在过滤函数的箭头函数array-callback-return结尾处返回一个值 - Expected to return a value at the end of arrow function array-callback-return on filter function 带有箭头函数回调的Array.prototype.filter()参数? (无此绑定) - Array.prototype.filter() argument with arrow function callback? (no this binding)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM