请问这段代码应该怎么优化


if (this.bizType === propertyProjectBizTypeKey.PROPERTY_RIGHT_TRANSFER) {
        return this.tagList;
      } else {
        if (this.jointTransfer) {
          return pullAllBy(this.tagList, this.tagList.filter(item => item.text === '待会同转让方审查'))
        } else {
          return this.tagList;
        }
      }

请问这段代码应该怎么优化

意思是两处返回tagList,想合并到一起呗?

 
if (this.bizType !== propertyProjectBizTypeKey.PROPERTY_RIGHT_TRANSFER && this.jointTransfer) {
        return pullAllBy(this.tagList, this.tagList.filter(item => item.text === '待会同转让方审查'));
            } 
    else {
          return this.tagList;
           }
      }

根据提供的代码,我看到你的代码中有两个 return语句。因此,你可以将它们简化为一个 return语句,如下所示:

if (this.bizType === propertyProjectBizTypeKey.PROPERTY_RIGHT_TRANSFER) {
 return this.tagList;
}

if (this.jointTransfer) {
 return pullAllBy(this.tagList, this.tagList.filter(item => item.text === '待会同转让方审查'))
}

return this.tagList;

改为:

if (this.bizType === propertyProjectBizTypeKey.PROPERTY_RIGHT_TRANSFER || !this.jointTransfer) {
 return this.tagList;
}

return pullAllBy(this.tagList, this.tagList.filter(item => item.text === '待会同转让方审查'));

在这种情况下,你只需要一个 return语句,这可以使代码更简洁、更易读。

if (this.jointTransfer && this.bizType === propertyProjectBizTypeKey.PROPERTY_RIGHT_TRANSFER) {
          return pullAllBy(this.tagList, this.tagList.filter(item => item.text === '待会同转让方审查'))
        } else {
          return this.tagList;
        }

if (this.jointTransfer && !this.bizType === propertyProjectBizTypeKey.PROPERTY_RIGHT_TRANSFER) {
  const filteredTagList = this.tagList.filter(item => item.text !== '待会同转让方审查');
  return filteredTagList;
} else {
  return this.tagList;
}