Skip to content

Instantly share code, notes, and snippets.

@jbcrestot
Created June 24, 2024 20:05
Show Gist options
  • Save jbcrestot/a5cc802ff053f8379c6aa3add892e1a4 to your computer and use it in GitHub Desktop.
Save jbcrestot/a5cc802ff053f8379c6aa3add892e1a4 to your computer and use it in GitHub Desktop.
an estonish example of buggy reduce
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