CodeSOD: Making the Thingie Work

This post was originally published on this site

The Daily WTF

Alyssa inherited some code from… well, she isn’t entirely sure from whom. There are names that come up in git blame, but even for some more recent commits, Alyssa has no idea who they are. Contractors? Interns? Randos pulled in off the street and handed a keyboard?

Based on the code quality, the last option is surprisingly likely.

const endpoints = mainThingie?.endpoints ?? []; const filteredWidgets: WidgetWithEndpoint[] = widgets.filter( (widget): widget is WidgetWithEndpoint => { if (!widget.endpoint) return false; return endpoints.map((mainThingieEndpoint) => _.isEqual(widget.endpoint, mainThingieEndpoint)).includes(true); }, );

The customers of this application are allowed to define their own custom widgets for certain pieces of data. The purpose of this block of TypeScript is to find all the widgets that map to this “Thingie”- and it’s worth noting, these names are not anonymized. widgets come from one backend service, while “Thingie”s come from another. Their endpoints (stored locally in each backend

To read the full article click on the 'post' link at the top.