Skip to content

Commit

Permalink
Fix use of array reduce without initial value
Browse files Browse the repository at this point in the history
  • Loading branch information
jstayton committed Aug 1, 2019
1 parent 5e57821 commit 39e834f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
10 changes: 3 additions & 7 deletions src/parsers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ class BaseParser {
}

buildValidationError(error) {
const detail = error.details.reduce((mostSpecific, detail) => {
if (mostSpecific && mostSpecific.path.length >= detail.path.length) {
return mostSpecific
}

return detail
})
const detail = error.details.reduce((mostSpecific, detail) =>
mostSpecific.path.length >= detail.path.length ? mostSpecific : detail
)

const path = detail.path.reduce(
(accumulator, value, index) =>
Expand Down
10 changes: 3 additions & 7 deletions src/validators/joi.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ class JoiValidator extends BaseValidator {
}

buildError(error) {
const detail = error.details.reduce((mostSpecific, detail) => {
if (mostSpecific && mostSpecific.path.length >= detail.path.length) {
return mostSpecific
}

return detail
})
const detail = error.details.reduce((mostSpecific, detail) =>
mostSpecific.path.length >= detail.path.length ? mostSpecific : detail
)

const path = detail.path.reduce(
(accumulator, value, index) =>
Expand Down

0 comments on commit 39e834f

Please sign in to comment.