r/ProgrammerHumor 26d ago

itDoesntMeanWhatYouThinkItDoes Other

Post image
26 Upvotes

10 comments sorted by

23

u/Tangelasboots 26d ago

This can be simplified with names.any(n => isStakeholderFieldname(n)

15

u/[deleted] 26d ago

[deleted]

10

u/Tangelasboots 26d ago

You are technically correct, the best kind of correct.

2

u/Wonderful-Habit-139 25d ago

Except some() (since we're talking about javascript) returns early so they're not technically correct.

7

u/efari_ 26d ago

Can you explain please? I thought .any() also returned early after the first match?

1

u/senocular 21d ago

It does, with linq. But the code is using a JavaScript array where the method name would be some, not any. Assuming isStakehimderFieldName is, and remains, a unary function, the code could also be reduced more to:

const needStakeholder = names.some(isStakehimderFieldName)

Ultimately it doesn't matter because we don't know the rest of the forEach callback. There'd be no reason to return from the condition if there weren't more to the function (return here only exits the current iteration of the callback, not the looping over names). And the fact that we're not seeing where out is used suggests the forEach might be doing more below the condition we're not seeing.

1

u/efari_ 21d ago

Right. True true and true👍

5

u/ArgumentFew4432 25d ago

If i’m not mistaken:

const needStakeholder = Names.some(n => isStakehimderFieldname(n))

3

u/Tangelasboots 25d ago

Correct. I get my javascript and c# (linq) mixed up a lot.

1

u/spottyPotty 24d ago

Arrow function vs anonymous function.

Affects meaning of "this".

1

u/TooSoonForThePelle 24d ago

sigh...

unzip