Skip to content

Commit

Permalink
refactor(utils): simplify findInField
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Aug 16, 2023
1 parent ab839a9 commit 0e3e5ba
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/utils/findInField.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@ export const findInField = memoize(
* @returns {?farmhand.plotContent}
*/
(field, condition) => {
/** @type {?farmhand.plotContent} */
let foundPlot = null

field.find(row => {
const matchingPlot = row.find(condition)

if (matchingPlot) {
foundPlot = matchingPlot
for (const row of field) {
for (const plot of row) {
if (condition(plot)) {
return plot
}
}
}

return matchingPlot
})

return foundPlot
return null
},
{
serializer: memoizationSerializer,
Expand Down

0 comments on commit 0e3e5ba

Please sign in to comment.