• Peter Newman (unregistered)

    Math.min(*array)

    Or

    Math.min.apply(null, array);

  • Me (unregistered) in reply to Peter Newman

    Kudos for not using the Frist word!

  • Biri (unregistered)

    Aaah, the wonders of the open space. I (and my headphones) know them well.

  • FatNoLife (unregistered)

    This is why companies can't have nice things

  • MiserableOldGit (unregistered)

    Leaving aside the basic lack of understanding why do people feel the need to reinvent the wheel like that? Just google it and look for the best answer? There's almost no problem we'd routinely encounter that hasn't been adequately solved by someone else before.

    Mind you, with JavaScript (like VBA and some others) you do need the judgement to wade through a lot of wrongness to find the truth!

    And open-plan, pffft, stop insulting our intelligence and telling us it's to do with team-work and collaboration when we all know it's about floor space per desk and saving money. Oh, and petty middle manglers who want to be able to pace around looking at everyone's screen to make sure they aren't goofing off on DailyWTF rather than churning out code.

  • Zenith (unregistered) in reply to FatNoLife

    I cringe every time I read "collaboration" in a job description because of incidents like this. You're never allowed to be smart in those situations. Directives always come from management or the worst developer with no involvement from anywhere in between. Then they can't figure out why the product is terrible, late, or, both.

  • Ronan (unregistered) in reply to MiserableOldGit

    @MiserableOldGit "Just google it"

    I’d bet this company has a very small whitelist of websites

  • Hasse the Great (unregistered)

    Took me 4 seconds to find the answer as of the first post: https://stackoverflow.com/questions/8934877/obtain-smallest-value-from-array-in-javascript

  • graceben (unregistered)

    I'd like to say thanks for the time you took compiling this article. You have been an inspiration for me. I've passed this on to one of my friends. academic essay writing

  • R (unregistered) in reply to graceben

    Go away

  • Chronomium (unregistered)

    Things like "half-open cubes" and "no specialists" sound good on paper.

    But computing is one of the few industries that has never been done on paper.

    (yes yes punch cards etc, don't let reality get in the way of a witty comment (attempt))

  • Sigh (unregistered)

    There's no timeframe given. Java & Javascript both existed before Google.

  • DQ (unregistered) in reply to MiserableOldGit

    Ah, Google That's how I learned about thedailyWTF.com Luckily I was clever enough to realize this isn't a site with best practices or we would have been in a lot of trouble :) (would have made a fun submission, though)

  • Alexander J. Vincent (github)

    it's worth asking "how big is the size of this array"? Or more specifically, "does it really matter in this case?" Sure, sorting is O(n ln n), but even a linear search is O(n). If the array is small, the difference isn't going to be significant.

    Look, I'm all for doing the job right, and I feel Max's pain here. (I write JS code for a living.)

    What Max should do is write up a testcase for his colleagues at https://jsperf.com/ and show them the difference.

  • Ex-lurker (unregistered)

    I think the lowest value seems to be Dalton's IQ.

  • Jaundicia (unregistered) in reply to Alexander J. Vincent

    No, what Max should do is find another job

  • slavdude (nodebb)

    We are all DevOps now!

    Am I the only one who thinks that in another 5-10 years having people who are focused on discrete areas of application development (front-end, middle-tier, testing, deployment, etc.) will be the next trendy thing?

  • Andrew (unregistered) in reply to Chronomium

    I once read a humorous list of "Real Computer Scientists ...," which included the following,

    "Real computer scientists never work in anything less dynamic than a #2 pencil." :-)

  • Parametamolcil (unregistered) in reply to Alexander J. Vincent

    it's worth asking "how big is the size of this array"? Or more specifically, "does it really matter in this case?"

    Right. This was Javascript, right, for the front end? I certainly hope the web page isn't displaying a list of 30000 values. Don't assume that a reduce with its interpreted call to another function is faster than a dedicated internal sort without testing it.

  • Shufflepants (unregistered) in reply to MiserableOldGit

    "Why do people feel the need to reinvent the wheel like that?"

    It's worse than that here. If they were merely reinventing the wheel, they'd be writing a small function to iterate over the array once while keeping track of the smallest element seen so far which would run in O(n) time still. What they're doing is reinventing the square wheel.

  • TheCPUWizard (unregistered)

    "Full Stack" usually good (seriously!)...however the way companies adopt (transition) is almost always horrible (and this is a good example).

    Also a big fan of collaboration, but again often it is done poorly. Having group space and private space (not necessarily dedicated to a person) is quite often near optimal, but found in less than 5% of environments.

  • Jim (unregistered)

    I kept expecting the solution to involve sorting the array for each comparison.

  • Carra (unregistered)

    Meh, that's not too bad. It's the difference between n & n log n. I expected them to find a n² algorithm.

  • John (unregistered) in reply to Carra

    @Carra: well, that's easy to achieve. Just use bubble sort, then take the first element. :-)

  • Vexorg (unregistered)

    Ah, the ever popular approach of getting "Full-Stack" developers by just calling everyone Full-Stack developers. My last role was one of those; mostly it means you end up with the devs doing the PMs jobs and the project managers trying to do dev work. You can probably guess the results.

  • Andrew (unregistered)

    Further WTF is the author calling it an n(lg n) operation....he doesn't understand big O notation any more than his colleague.

  • Herby (unregistered)

    The underlying WTF is that nobody went to school. There they would have have been taught all about sorting, and how long it takes. It is one of the first lessons given (see Knuth). Some of the "first principles" should be studied. Those that hack away at Excel and Access just think they "know", but they actually don't. They don't even have the foresight to use some of the tools (google is your friend!).

    Yes, for the most part, sorting is an n*(log n) operation. I suspect that with this task, the sort (on the same data) might be used for other purposes, but then WTFery would come in, and a sort would be done multiple times. Oh, well....

  • muteKi (unregistered) in reply to Shufflepants

    I'd say, it's probably closer to reinventing the trackball. Sure, it can be set up to work like a wheel, but it does a lot more than it needs to if it's just going to be a wheel, is still relatively impractical for the purpose, but is useful in other circumstances (i.e., sorting a list is more useful than a square wheel). It does (more-or-less) solve the problem, just adds a lot of cruft that people will have to deal with down the line as things get more complex.

    To put it another way, I can find a lot more uses for a sorted list than for a square wheel.

  • siciac (unregistered)

    There they would have have been taught all about sorting, and how long it takes.

    Do you have to go to school to observe that when you're looking for a minimum value in a list, you typically point your finger at the list, and trace through it, noting the lowest value you've seen?

    It seems like most coders write algorithms like a retarded toddler with puzzle pieces, randomly banging them together until something looks like it fits.

  • siciac (unregistered) in reply to Andrew

    Oh, and why do people seem to think object construction is free? This is absurdly common, even in loops: { v:k for k, v in foo.items() }[x]

  • That sounds fine for the front end (unregistered)

    Why would you ever be returning an array to the front end that's long enough that it matters how you sort it?

  • Avium (unregistered) in reply to siciac

    That's exactly how I work with regular expressions.

  • Omego2K (unregistered) in reply to That sounds fine for the front end

    I think the issue is a choice between two approaches of equal effort is the least efficient one.

  • Derf Skren (unregistered)

    +1 for mentioning HO scale.

  • siciac_is_onto_me (unregistered)

    Damnit, don't describe my way of coding. Then I'll have to compete with other no-skill 'developers' who just jam frameworks and code together until I get the damned return codes I was looking for! What next, you'll tell them how to copy and paste stackoverflow? Well joke's on you- I cover my tracks by renaming the variables and functions. Ha!

  • Gerry (unregistered) in reply to Chronomium

    Or coding sheets - https://mainframesupport.wordpress.com/tag/coding-sheet/ In my first job in 1982, there was an experienced* COBOL coder who has to be forced to use a keyboard, rather than having a data entry person key it in from a codeing sheet.

    From other people's description he may have had 1 year of experience repeated 15 times. I wasn't a coder, so I can't say.

  • Quite (unregistered)

    ... and Max calmly backed up all the personal content on his machine onto his thumb drive, cleared down his email, logged out of his computer, put all his personal effects from his desk into his briefcase, and walked out of the office never to return.

  • FTB (unregistered)

    The real WTF is expecting a language to have a built-in function for EVERYTHING and then your brain falls out if there isn't one for what you want to do.

  • shcode (unregistered)

    why was Max, the disruptive one, the only one of the three who sounded remotely like he even knows what programming is?

  • eric bloedow (unregistered) in reply to Andrew

    you made me think of this story: https://thedailywtf.com/articles/classic-wtf-the-proven-fix

  • This is why... (unregistered)

    ...one of my interview questions is about the work environment. If it isn't at a minimum full-height cubes, I'm probably not interested.

  • dj (unregistered) in reply to Alexander J. Vincent

    here you go: https://jsperf.com/wtfarray

  • Fred Nerks (unregistered) in reply to Derf Skren

    -1 for not knowing it is called H0.

  • Alexander J. Vincent (github) in reply to dj

    Thanks, that's actually useful - and does prove Max's point as I suspected it would. Just out of curiousity, could you add reduce using Math.min(a, b)?

    Addendum 2017-07-25 15:41: Specifically,

    var smallest = a.reduce(Math.min);

  • Uri (unregistered)

    If you want the minimal element, surely you shouldn't ask Max.

  • David Mårtensson (unregistered) in reply to Sigh

    Well, filter as a method on Javascript Arrays did not exist before Google ;) It was defined in ecmascript 5.1 in 2011. http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.20

    So we know Google existed :D

  • Laura Vitto (unregistered)

Leave a comment on “Finding the Lowest Value”

Log In or post as a guest

Replying to comment #:

« Return to Article