Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I feel like you are just sorting objects via their name properties ascii values. Nothing fancy
-
@PrivateGER
Inside of a sort, creates a size(1) tuple of an array by spreading a Set consisting of known tags+name of the given argument into an array. Apparently there's a function on the inKeywords object named included that expects that structure, and will likely do an O(n^m) comparison to satisfy the filter predicate.
It does this for both args and then compares the length of the filter expression size, which I can only assume to be size(1) or size(0) given the resulting filter expression is operating on a size(n) tuple at position 0 and will therefore only apply the predicate to a single argument (he's exploiting binary coincidence). This expression is for some ungodly reason executed twice in a cascading ternary that allows it to be less than or equal than the resulting length. My guess is because the author of the function isn't aware that <== exists.
All of that is done to determine the order in which objects containing tags are sorted.
Before anyone says it, autism has higher standards than this. This is just shit. If I had to guess, the algorithm started as an attempt to O(1) compare all the values in the set to another set, but then realized there were sets on both sides of the predicate and you needed to compare all of members of both sets. Rather than update the code, he decided to lavaflow the Set into an array, but didn't realize this needs a double spread. He then updates the argument to accept the tuple instead and destructures the arg in the includes predicate function. It's the essence of laziness. -
@SortOfTested Catamorphisms, especially if they are of the garden variety are definitely more pettable than hylomorphisms. Don't let them near your trees though, they either completely reduce them with their nails, or get stuck in the branches. Coincidentally, if you are chasing after tails, you might want to adopt a garden variety paramorphism.
-
KDSBest7755y@SortOfTested I'm impressed. I'm not sure if I'm more impressed by the story of how this thing was created of yours or that you actually read the code.
I saw the code and was thinking, I'm happy not to have to deal with such a thing and I've seen way worse in my past. Maybe even created worth code decades ago.
But you impressed me, doesn't happen often. Made my day :)
Related Rants
Just found this javascript one-liner gem:
array.sort((a, b) => ([...new Set([...this.strip(a.name), ...a.tags])].filter(x => inKeywords.includes(x))).length == ([...new Set([...this.strip(b.name), ...b.tags])].filter(x => inKeywords.includes(x))).length ? 0 : (([...new Set([...this.strip(a.name), ...a.tags])].filter(x => inKeywords.includes(x))).length < ([...new Set([...this.strip(b.name), ...b.tags])].filter(x => inKeywords.includes(x))).length ? 1 : -1))
If that doesn't make you angry you might be in a coma
rant
js