Created
June 24, 2024 20:05
-
-
Save jbcrestot/a5cc802ff053f8379c6aa3add892e1a4 to your computer and use it in GitHub Desktop.
an estonish example of buggy reduce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const defaultResults = { | |
default: [], | |
prolyConjugated: [], | |
femininePlural: [], | |
conjugated: [], | |
renderCount: 0, | |
}; | |
const getFilteredResults = (data: string[]): FilteredResults => { | |
return data.reduce<FilteredResults>( | |
(acc, word) => { | |
if ( | |
word.endsWith("AI") || | |
word.endsWith("AT") || | |
word.endsWith("AIT") || | |
word.endsWith("ONT") || | |
word.endsWith("EZ") | |
) { | |
acc.conjugated = [...acc.conjugated, word]; | |
} else if (word.endsWith("A") || word.endsWith("ENT")) { | |
acc.prolyConjugated = [...acc.prolyConjugated, word]; | |
} else if (word.endsWith("S") || word.endsWith("EE")) { | |
acc.femininePlural = [...acc.femininePlural, word]; | |
} else { | |
acc.default = [...acc.default, word]; | |
} | |
return acc; | |
}, | |
defaultResults | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment