As a self-taught web developer going on 25 years now I am sympathetic and if it helps you out at all I would have failed that question coming at it the way you were coming at it -- but I wouldn't have come at it that way.
Below is a super simple solution, using the Intl.collator; a built-in Javascript comparator. I offer it not to make you feel bad, but because the other questions they asked Object.freeze and requestAnimationFrame sounded to me like they were more interested in your breadth of knowledge over Javascript and some of the more esoteric APIs than computer science; maybe? Don't get me wrong Object.freeze, Request Animation Frame, etc. are all useful but not something I deal with every day or even every year -- not in the corporate space anyway.
Online since 1990 Yes! I started with Gopher. I do modern Web Component Development with technologies supported by **all** WHATWG partners (Apple, Google, Microsoft & Mozilla)
Online since 1990 Yes! I started with Gopher. I do modern Web Component Development with technologies supported by **all** WHATWG partners (Apple, Google, Microsoft & Mozilla)
Yes, indeed. Same concept: sort characters.
It also shows why tech interviews are required. You need a balanced team of developers to bounce ideas around like a soccer team bounces the ball around and one person (and the whole team) scores. So Raul was declined the job because:
A. He did not fit in the team (they already have enough people who can't sort)
B. They are a company who only want Guru developers (in which case they will eventually fail, because a team of Guru developers will never ask the "stupid" questions that drive innovation) Its the famous Think Different Apple video. You need misfits in a team.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
As a self-taught web developer going on 25 years now I am sympathetic and if it helps you out at all I would have failed that question coming at it the way you were coming at it -- but I wouldn't have come at it that way.
Below is a super simple solution, using the
Intl.collator
; a built-in Javascript comparator. I offer it not to make you feel bad, but because the other questions they askedObject.freeze
andrequestAnimationFrame
sounded to me like they were more interested in your breadth of knowledge over Javascript and some of the more esoteric APIs than computer science; maybe? Don't get me wrong Object.freeze, Request Animation Frame, etc. are all useful but not something I deal with every day or even every year -- not in the corporate space anyway.Strictly speaking I would instantiate the comparator externally, but it looked like they wanted it all inside the function body. ¯_(ツ)_/¯
Oh, thanks for sharing. I still haven't used Intl API yet so I couldn't imagine there was such a thing to do this easily.
I'll definitely take a look on it, appreciate that!
Wow, brilliant 1-liner solution! I didn't know anything about
Intl.Collator
. I investigated a little bit more about it. This also works:This is the original solution I came up with in 17 min. (I timed myself to make sure I don't go over 30 min)
You are all still thinking in Numbers. (including those who interview)
The localCompare won't sort "2.1.0a" properly
Key is to convert Numbers to Letters, so 2.1.0a becomes cbaa and then sort
explanation:
stackoverflow.com/questions/683259...
Or in one line
`
Or just do something like "2.1.0a" becomes " 2 1 0 a", then it will sort correctly.
Yes, indeed. Same concept: sort characters.
It also shows why tech interviews are required. You need a balanced team of developers to bounce ideas around like a soccer team bounces the ball around and one person (and the whole team) scores. So Raul was declined the job because:
A. He did not fit in the team (they already have enough people who can't sort)
B. They are a company who only want Guru developers (in which case they will eventually fail, because a team of Guru developers will never ask the "stupid" questions that drive innovation) Its the famous Think Different Apple video. You need misfits in a team.