- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
min(frist)
Admin
What incompetence! Everyone knows the best way to swap two numbers is to use three XORS.
Admin
I've found an easter egg on the post. Try clicking on the word "pest".
Admin
I'm not sure how Phlogiston theory and Relativity can even be compared. Are you sure you're not thinking of luminiferous aether?
Admin
Are you sure that isn't part of the joke?
Admin
It's a Remy post. That stuff's normal.
Admin
That's not always reliable in JS although would probably work fine here, as like as the input types can be juggled into an accurate int type.
The funniest solution for this problem I have seen is: (...args) => args[0] === args.sort()[1]
It works quite well all things considered, if you can figure out how to use it and what it's meant to do.
Admin
In Phlogiston theory min and max are the same so the code is fine.
Admin
Considering someone just posted an interview question about JS to one of the StackExchange sites, to wit:
Can the following ever evaluate to TRUE if (a ==1&& a==2&&a==3)
And people posted two completely different, allowable, valid solutions, I think I don't want ever to learn JS. (FWIW, I would have gone with a third, valid solution of operator overloading) ref: https://stackoverflow.com/questions/48270127
Admin
Remy, I'm sorry you couldn't find better friends.
regards,
Marcus PS: My last name was Phlogistein, you little twerp.
Admin
Great idea!
min = min ^ Math.max(min,max); max = max ^ Math.min(min,max); min = min ^ Math.max(min,max);
Admin
I think any language that supports property getters that can run code can do this, not only Javascript.
Admin
Apparently I'm an idiot but how does: min = Math.min(min, max); max = Math.max(min, max); set both to equal to the lowest of the two?
Admin
just reread it - never mind... I am an idiot
Admin
Property getters that run code can easily be abused, but I wouldn't say it is wrong in all cases. Typically I use them in an object to lazy-load an item that much of the time is never used and only needs to be there if it does get used - so the getter will initialize its backing property if it hasn't already been done. Of course, this is typically only done with read-only properties. (.Net by the way)
Admin
Something about assertions in source never felt right. Better to filter.
lodash has an xor
Admin
OK. I'm stupid. I couldn't spot why the min/max thing does what Remy says it does, until I realised that for no very good reason the code treats the function parameters as sacrosanct in some way, and buggers everything up by reusing the variable names. This is of course sick and silly.
Which would lead the average minimally talented ape to realise that neither integer, on the way in, is constrained to be either a max or a min. I'm quite surprised that they didn't include checks for one of them being an arithmetic mean, a geometric mean, or even a median. (God knows how that would work, but it couldn't be less awful.)
I'm getting old. So very old. I am increasingly drawn to languages like Haskell, which I basically do not understand at all, but which puts a huge emphasis on describing the contract of the function by actually giving the parameters a proper type, or type alias. Passing anything sane like, say, range in this case would obviate absolutely all the rest of the rubbish. Fifty thousand, pah.
(And yes, I am aware that you can do this in either JavaScript or PHP. But apparently you are trained to do the stupid thing instead.)
Admin
Or add and subtract considering values are numbers.
Admin
Sole Purpose of Visit, comment held for moderation seems to hate you.
Admin
The really important question is: Does that expression ever evaluate to FileNotFound?
Admin
I still don't see the problem with the min/max swapping thing. It looks OK to me. Anyone care to explain why the swap wouldn't work ?
Admin
For anyone who like me had a hard time figuring out why this code sets both variables to the lower of the two if min>max.
Now let's see what happens:
min is now set to 5, because the varialbe max is 5, min is 20.
Aha!Now we are doing this: max = Math.max(5,5). Which (very unsurprisingly, even for JavaScript) is 5. Congratulations, both variables now hold the value of 5.
Admin
"min is 20."
This, of course, should've read "was 20".
Admin
The client uses a price of 0 to indicate 'not for sale', and has no products approaching 50k. A user who fills out the minimum and does not fill out a maximum greater than the minimum is treated as requiring an exact match.
Lack of comments in the self-documenting code is TRWTF.