for (const field in issueFieldType) {
const type = issueFieldType[field];
if (!type) {
delete issue[field];
} else if (type === 'required' && !issue[field]) {
return `${field} is required.`;
}
}
we see that the if (!type) is redundant. because every type in issueFieldType is not undefind .
I think we should write issue instead of issueFieldType in the for statement:
for (const field in issue) {
const type = issueFieldType[field];
if (!type) {
delete issue[field];
} else if (type === 'required' && !issue[field]) {
return `${field} is required.`;
}
}
The resulted function is:
function validateIssue(issue) {
for (const field in issue) {
const type = issueFieldType[field];
if (!type) {
delete issue[field];
} else if (type === 'required' && !issue[field]) {
return `${field} is required.`;
}
}
if (!validIssueStatus[issue.status])
return `${issue.status} is not a valid status.`;
return null;
}
If we see this part of
validateIssue
function:we see that the
if (!type)
is redundant. because everytype
inissueFieldType
is notundefind
. I think we should writeissue
instead ofissueFieldType
in thefor
statement:The resulted function is: