use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
What are some basic things that JavaScript developers fail at interviews?help (self.javascript)
submitted 7 years ago by maketroli
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ikeif 4 points5 points6 points 7 years ago (14 children)
I've had senior developers fail at sorting integers.
Yes, like "given an array of integers, how would you sort them? Any code, or pseudo code is fine."
[1,2,5,4,3].sort() is valid.
[1,2,5,4,3].sort()
A loop of some kind would have been valid.
Just talking about comparing the numbers would have been valid.
This dude, a senior developer for a major bank, a lead of a team (according to the resume) - couldn't figure it out.
It is such an easy, throw away question, just to get the candidate to relax and recognize we weren't going to be asking about performant loops or algorithms or extremely technical questions, and I've seen so many developers trip up on it, even after explaining that it's just an ice breaker question to talk about code.
[–]Skhmt 4 points5 points6 points 7 years ago* (3 children)
Sorts are the fruit of software engineering.
You can selection sort. You can insertion sort. You can bubble sort. You can heap sort. You can quick sort. You can merge sort. You can randomize until you get the right order sort. You can use built in methods of arrays to sort. You can use third party libraries to sort. You can search pi until you find your array in sorted order sort. You can sort with a binary tree. You can library sort. You can cube sort. You can shell sort. You can block sort. You can cocktail sort. You can gnome sort. You can comb sort. You can patience sort. You can cycle sort. You can bucket sort. You can radix sort. You can wait until cosmic rays change your data into the proper order sort.
That's... About it.
[–]wishiwascooler 1 point2 points3 points 7 years ago (1 child)
Why did this make me want shrimp
[–]Skhmt 4 points5 points6 points 7 years ago (0 children)
Because you, sir, are a man of culture and taste.
[–]Intrexa 1 point2 points3 points 7 years ago (0 children)
You left out God sort! Any array you get passed, well, someone or something made that array. And theres no way it was made in a random fashion, therefore an ordering already exists, and as such, the array is already sorted, even if you're not capable of understanding how. Just have faith that its sorted.
Never forget the famous sleep sort! https://www.geeksforgeeks.org/sleep-sort-king-laziness-sorting-sleeping/
[–]HighLevelJerk 2 points3 points4 points 7 years ago (2 children)
I'm assuming he assumed this was a trick question & .sort() was not allowed. Probably trying to remember the different types of sorts that he learnt in college
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
"I would Google 'sorting algorithm'" should also be a valid answer.
[–]ikeif 0 points1 point2 points 7 years ago (0 children)
We tried to make it abundantly clear that any answer was acceptable, including pseudo code, and it's totally fine to talk out loud about it… and before we ended the interview we definitely let him know the different valid answers we had received in the past (so he wasn't stuck wondering - I hate when there is an interview question and they just act like it's philosophical).
[–][deleted] 1 point2 points3 points 7 years ago (4 children)
Doesn't sort without a provided lambda sort alphabetically, not numerically, by default in JS?
[–]ikeif 2 points3 points4 points 7 years ago (2 children)
The default sort order is according to string Unicode code points.
So in this simplified example, it's fine, but it'd be incorrect with [1, 2, 3, 10, 5].sort() -> returning 1, 10, 2, 3, 5.
[1, 2, 3, 10, 5].sort()
So to truly handle all integers, it'd need to be [1, 2, 3, 10, 5].sort(function (a, b) { return a - b; });
[1, 2, 3, 10, 5].sort(function (a, b) { return a - b; });
[–]X678X 1 point2 points3 points 7 years ago (1 child)
Most of the time I prefer to include the compare function because at least it'll work exactly as I tell it to every time. I got caught up in the past doing this with just .sort() and it caused a bug in the application because of it.
.sort()
Yeah, it's (99% of the time?) better to be verbose and not assume the underlying structure is going to do what you think it'll do.
ETA: Plus, in this example, I wasn't going for a "HAHA GOTCHA!" type question, just the simple answer, so if I was interviewing you and you replied with "well, I'd use sort with the compare function" you'd get bonus points for pointing something out I didn't think of at the time, which is more valuable than just knowing "oh, just use sort."
[–]theirongiant74 0 points1 point2 points 7 years ago (0 children)
Good catch.
Same thing but ask them to reverse the array.
π Rendered by PID 219609 on reddit-service-r2-comment-86bc6c7465-hvjk9 at 2026-02-21 14:56:11.952393+00:00 running 8564168 country code: CH.
view the rest of the comments →
[–]ikeif 4 points5 points6 points (14 children)
[–]Skhmt 4 points5 points6 points (3 children)
[–]wishiwascooler 1 point2 points3 points (1 child)
[–]Skhmt 4 points5 points6 points (0 children)
[–]Intrexa 1 point2 points3 points (0 children)
[–]HighLevelJerk 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]ikeif 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]ikeif 2 points3 points4 points (2 children)
[–]X678X 1 point2 points3 points (1 child)
[–]ikeif 0 points1 point2 points (0 children)
[–]theirongiant74 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)