TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Sorting - We're Doing It Wrong

66 pointsby cheeaunalmost 13 years ago

8 comments

gooderlookingalmost 13 years ago
Maybe I'm the only one who missed the memo, but in case anyone else is wondering what a hash is doing in JS:<p>"When writing (in text, not in JavaScript) about properties on specific prototypes, you may use the JavaScript notation, foo.prototype.bar. However, this shorter (non-JavaScript) notation is often used instead: foo#bar. Basically, the hash (#) stands for .prototype. — fancy huh?"<p><a href="http://mathiasbynens.be/notes/javascript-prototype-notation" rel="nofollow">http://mathiasbynens.be/notes/javascript-prototype-notation</a>
评论 #4085605 未加载
评论 #4085480 未加载
评论 #4085213 未加载
评论 #4086178 未加载
tantaloralmost 13 years ago
This is fixed in Python:<p>The sort() method takes optional arguments for controlling the comparisons.<p>"key" specifies a function of one argument that is used to extract a comparison key from each list element.<p>In general, the key and reverse conversion processes are much faster than specifying an equivalent cmp function. This is because cmp is called multiple times for each list element while key and reverse touch each element only once.<p><a href="http://docs.python.org/library/stdtypes.html" rel="nofollow">http://docs.python.org/library/stdtypes.html</a>
Camilloalmost 13 years ago
For a moment, I thought there was actually something new about sorting. That turned out not to be the case, of course.<p>I understand the importance of linkbait titles, but specifying the context (e.g. "we're doing it wrong in JavaScript") would save people time without weakening the impact on those who might be interested in the article (JavaScript developers).
评论 #4087273 未加载
TamDenholmalmost 13 years ago
This is a very cool visualiser that was posted on HN before if anyone feels like playing: <a href="http://visualsort.appspot.com/" rel="nofollow">http://visualsort.appspot.com/</a>
评论 #4085004 未加载
numeromanceralmost 13 years ago
This is worth reading for that video alone. Mergesort was particularly cool.
ruxkoralmost 13 years ago
javascript sorting: having expected a sorting somewhat similar to python and being very... surprised that javascript essentially sorts everything but primitive types by comparing their String counterparts, I decided to implement a more sensible compare function, similar to e.g. python:<p><a href="https://gist.github.com/2772234" rel="nofollow">https://gist.github.com/2772234</a><p>I am currently using this in server only environments, so there is no comparison for DOM elements.
lliiffeealmost 13 years ago
Wow-- apparently Mergesort can be implemented in-place!?
评论 #4085402 未加载
评论 #4087156 未加载
评论 #4086389 未加载
Rickasaurusalmost 13 years ago
Another great example of Javascript being awful.
评论 #4086889 未加载