• astrsk@fedia.io
    link
    fedilink
    arrow-up
    13
    ·
    24 hours ago

    That sort is pretty bonkers. I agree with the no hire because it doesn’t really display an understanding but if I got that as an answer in a technical interview, it would be fun to dive into why that code was written and might turn into a hire if we peer just a bit deeper under the hood of the thinking. This is why “solve for x” technical questions suck unless you make the actual interview about the back and forth. Assume a correct premise if it works and tweak and change and poke and prod to really sus out if they understand what and why that was written.

  • PhilipTheBucket@ponder.cat
    link
    fedilink
    arrow-up
    23
    ·
    1 day ago

    For-loop even number guy can get lost. Sleep-sort guy I would at least be interested to see the rest of the test. As long as he has an awareness of when not to do that kind of thing in production code, it actually might indicate he has some ability.

    • aberrate_junior_beatnik@midwest.social
      link
      fedilink
      English
      arrow-up
      4
      ·
      16 hours ago

      For-loop even number guy can get lost

      I don’t get this. Who cares if they forgot or just didn’t know the better solution? They were able to solve the problem under pressure, even if not in the most optimal way. They even remembered to handle the negative case, which is straight up a good sign (no pun intended). And while it’s slow, it would honestly still be fine to use in production anywhere you’d use typescript, as long as it’s not in a hot spot.

      In my mind this tells me approximately as much about the programmer as if they wrote it using modulo.

      • PhilipTheBucket@ponder.cat
        link
        fedilink
        arrow-up
        7
        ·
        16 hours ago

        It’s really just not a good solution. It’s more complex, it’s way slower, it shows they’re not familiar with stuff they really should be familiar with.

        Anyone who struggles to write a function to determine evenness of a number, and has to throw in some crazy solution to be able to make it across the finish line, is going to really struggle with real production code. They’re going to produce stuff that’s going to make everyone’s job a lot more difficult.

        return (x % 2) == 0;
        return (x & 1) == 0;
        return (x / 2 * 2) == x;
        return x/2 == (x+1) / 2;
        

        You can come up with unusual solutions and it can be fine. You can’t come up with cockamamie solutions, that’s why you’re doing the test.

  • Admiral Patrick@dubvee.org
    link
    fedilink
    English
    arrow-up
    19
    ·
    edit-2
    1 day ago

    Good news: The Loops embed feature has moved to beta.

    https://tesseract.dubvee.org/c/loops@midwest.social

    If anyone is willing/able to test through the hosted instance (linked above) and submit any bugs they may encounter, it would be greatly appreciated :)


    On the array sort…that is clever but it doesn’t return those values to something you can use; it just sorts them on screen. I respect the cleverness, but yeah, not useful.

    • aberrate_junior_beatnik@midwest.social
      link
      fedilink
      English
      arrow-up
      3
      ·
      16 hours ago

      On the array sort…that is clever but it doesn’t return those values to something you can use; it just sorts them on screen. I respect the cleverness, but yeah, not useful.

      This is not the reason it isn’t useful. The function could just as easily modify an array as print; you could also keep a list (or an atomic integer if that functionality is available) of which have been sorted and spin until it shows that every member has been sorted. Taking n milliseconds to sort an array whose highest element is n, with the cost of all of the thunks, plus the potential for a (very rare) race condition… not so great.

      Regardless, I’d hire either of these programmers if there weren’t red flags elsewhere.

      • Cris@lemmy.world
        link
        fedilink
        English
        arrow-up
        5
        ·
        edit-2
        1 day ago

        Hey, is there any chance it might make sense to slow down the rate at which loops are posted?

        I really enjoy seeing them on my feed, but if I’m subbed to the loops comm it just floods literally everything else and every other post is a loop with a vertical thumbnail twice the height of other posts. Edit: just checked and it’s actually several loops for every other post 😅

        If it’s not something that makes sense for the comm that’s fine, I just wanted to ask :) engagement seems like it might also be a bit higher with a more limited selection of posts

        Hope you have a lovely day :)

        • m_f@midwest.socialOPM
          link
          fedilink
          English
          arrow-up
          4
          ·
          1 day ago

          Thanks for the feedback! Would it help if I used something like schedule.lemmings.world to spread the posts out over the day?

          • Cris@lemmy.world
            link
            fedilink
            English
            arrow-up
            2
            ·
            edit-2
            1 day ago

            I think that would help a lot! There are just so many of them in quick succession that it’s really easy for them to drown out all the other stuff I’m subscribed to

            Thanks for the work you do running this community and posting stuff for folks, it’s appreciated :)

    • ScreamingFirehawk@feddit.uk
      link
      fedilink
      arrow-up
      15
      ·
      22 hours ago

      It doesn’t, the array is still in the same order it started in, it’s members are just printed to the console in numerical order.

      It just prints the number 1 after 1 ms, 2 after 2 ms, 3 after 3 ms etc.

      • Randelung@lemmy.world
        link
        fedilink
        arrow-up
        7
        ·
        21 hours ago

        Instead of print you could add them to a second array, though. Even clear the original first for “in place” sorting; never mind the memory allocation for the lambdas.

  • Cris@lemmy.world
    link
    fedilink
    English
    arrow-up
    10
    ·
    1 day ago

    That’s honestly so cool lol. Fun to see logic problems solved in really inventive ways

  • TootSweet@lemmy.world
    link
    fedilink
    English
    arrow-up
    7
    ·
    1 day ago

    I don’t have any interview stories. Alas, I’ve only given a couple of interviews. (Or maybe rather fortunately I’ve only given a couple of interviews, depending how you look at it.)

    But I do remember a first code review for one guy. Dude implemented his own bubble sort rather than using a sort method from the standard library. Aside from that one interesting choice, he was a good coder as I recall. He’s a manager now.

    • m_f@midwest.socialOPM
      link
      fedilink
      English
      arrow-up
      5
      ·
      1 day ago

      I did a review of someone’s code submission once where they pretty much wrote a bespoke JQuery implementation to handle the super-complex task of incrementing a number in a div when a button is pressed. I don’t think they got the job. I felt a little bad for them, but a valid part of those coding interviews is “Will this person go off and do something crazy like write their own half-baked React instead of just using React?”. Showing that you know how to write code as simply as possible is a big plus.

    • astrsk@fedia.io
      link
      fedilink
      arrow-up
      3
      ·
      24 hours ago

      I have yet to administer or discuss interviews where using an api was an acceptable answer. Granted my experience is more on the engineering side but it seems odd to me to not expect someone to implement their own algorithm. If they had 60 seconds to answer a multiple choice technical question on a prescreen online test, maybe. But it seems that person demonstrated their understanding on a technical level that should have been expected and explored?

      • TootSweet@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        10 hours ago

        Oh. Oh no. You misunderstand. My story was about one of the first pull requests a guy opened after he was hired. He put his home-grown bubble sort in code that would have ended up in production in an e-commerce application had I not pointed him to the sort functionality in the standard library.

        • astrsk@fedia.io
          link
          fedilink
          arrow-up
          3
          ·
          5 hours ago

          Oh my, I definitely missed something when reading lol. That’s insane behavior! I hope he learned from the mistake.

  • Orbituary@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    1
    ·
    1 day ago

    Sorry, but, I think all my coding would go out the window and I’d start making some nonsense up if she was interviewing me.

  • Kraiden@kbin.earth
    link
    fedilink
    arrow-up
    4
    arrow-down
    8
    ·
    1 day ago

    I’m sorry, but even without knowing about the mod operator, this is inefficient and over engineered. Why have a loop at all?

    fun isEven(n: Int){
        return n == abs(n)
    }
    

    no loop required…

    having said that, I can totally see how that was missed in a high pressure interview. I hate interviews like that!

    edit: Ha ha… isEven…not isPositive… I’m tired. ignore me!

    • lobut@lemmy.ca
      link
      fedilink
      arrow-up
      11
      ·
      edit-2
      24 hours ago

      Because the abs(3) == 3 is true and that isn’t even.

      An even number of flips would be true and an odd number of flips would be false which works out.

      I was thinking a bitwise & or converting it to a string and testing if the right most character is 0, 2, 4, 6, 8 would be panic mode solutions too.

      • Kraiden@kbin.earth
        link
        fedilink
        arrow-up
        2
        ·
        21 hours ago

        you might be able to do it with a bitwise op? My track record tonight is not great so I’m not going to comment. Have a look at @ImplyingImplactions comment for a loopless solution

        • UID_Zero@infosec.pub
          link
          fedilink
          English
          arrow-up
          2
          ·
          18 hours ago

          Bitwise and with 0x1. If result is 0, it’s even. Least significant bit is always 1 for odd numbers.

    • ImplyingImplications@lemmy.ca
      link
      fedilink
      arrow-up
      8
      ·
      23 hours ago

      That would be isPositive.

      Without using the modulo operator you’d essentially have to reimplement it. Divide the number by 2 and round down. Multiply that by 2 and then subtract it from the original number.

      isEven(10) results in 10-10==0 (true) whereas isEven(13) results in 13-12==0 (false).

      function isEven(n){
        n = Math.abs(n)
        return (n - (Math.floor(n/2) * 2)) == 0
      }
      
      • dream_weasel@sh.itjust.works
        link
        fedilink
        arrow-up
        4
        ·
        edit-2
        18 hours ago

        Minor simplification: this works even without taking absolute value first of you use fix instead of floor.

        Edit: I don’t know if fix is in the stock math library on second thought…

      • Kraiden@kbin.earth
        link
        fedilink
        arrow-up
        5
        ·
        21 hours ago

        Yep! I’m wrong. Pretty embarrassing!

        That’s a nice solution though! Gonna have to try and remember that one!