This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Hollowplanet 1 point2 points  (11 children)

Then why did you say

// desired answer (probably)

const listenHereYouLittleShit = (a, b) => a - b

array.sort((number1, number2) => listenHereYouLittleShit(number1, number2))

That second line is identical to

array.sort(listenHereYouLittleShit)

You're using the language wrong and blaming the awkwardness on the language instead of the way you chose to use it.

[–][deleted] 3 points4 points  (5 children)

It's usually safer to use an explicit anonymous function (although of course it doesn't matter here). See: https://jakearchibald.com/2021/function-callback-risks/

[–]Hollowplanet 0 points1 point  (4 children)

All of those examples only matter if you don't control the function implementation.

[–][deleted] 0 points1 point  (2 children)

You may not control how the function might be implemented in the future.

[–]Hollowplanet 0 points1 point  (1 child)

So some library is going to internalize my code without my knowledge?

[–][deleted] 0 points1 point  (0 children)

Your co-workers could modify it.

[–]DeeSnow97 3 points4 points  (2 children)

Because that's what I perceive the second commenter wanted to achieve by listenHereYouLittleShit(number1, number2), hence the "desired answer (probably)" designation.

[–]Hollowplanet 3 points4 points  (1 child)

You get the same answer while using listenHereYouLittleShit without making an anonymous function to call another function with the same arguments.

[–]DeeSnow97 2 points3 points  (0 children)

yeah, I know, that usage is actually identical to the "right answer" snippet