No, the compare function needs to be able to indicate when two values are equal, not just when one is smaller/larger than the other. Otherwise your sort function will return inconsistent results for compare(a, b) and compare(b, a) when both values are equal.
You might find Rosetta Code to be useful - it's a wiki site with hundreds of examples, all with solutions in dozens of languages for comparison.
ikewise, I felt a little let down.
On the flipside, it's an excellent opportunity to bring Rosetta Code to people's attention - a wiki with hundreds of example problems, each solved in many languages for comparison!
I find it invaluable in that sort of mid-learning level of a new language, where I have the syntax sorted, but I need lots of programs small enough to hold in my head, but also large enough to show off all the features, to learn and read. Here's Dijkstra, for example: https://www.rosettacode.org/wiki/Dijkstra%27s_algorithm
for...of is easier to read and recognize as a loop construct at first glance, and as far as I recall it's also faster nowadays since the body of the loop is inline, whereas forEach requires the runtime to deal with a function object.
Makes me wonder if maybe the syntax for mapping, folding and other collection operations should have a similar syntax to for instead of the current method-style syntax popular in most modern languages.
for each(str from [list: "Ahoy", "world!"]):
for map(n from [list: 1,2,3]): n * n end
# ==> [list: 1, 4, 9]
for filter(n from [list: 1, 2, 3]):
n >= 2
# ==> [list: 2, 3]
for fold(sum from 0, n from [list: 4, 5, 6]):
sum + n
# ==> 15
Thanks for the site! Do you have thoughts on removing all the print/console.logs calls on every line? It feels like there's a lot of visual noise there, that can still be met with the comments showing state/output.
Do people actually use cheat sheets like this? IMO, the first stackoverflow result in google is generally what I'm looking for and quicker - especially for common things and common languages such as the things on this page. Even if you have the page bookmarked, you still need to find/search/scroll for the specific thing you're looking for. Also, with Alfred you can google anything even quicker by not having to cmd+tab to the browser.
When I publish code about algorithms and data structures to my web site, I usually offer multiple language versions. Why? Because understanding the computer science theory and math proofs is a big effort. Writing and debugging my first implementation in any language is a big effort. But porting that code to a bunch of languages is comparatively easy and is almost a thoughtless mechanical process.