It would still be possible to hardcode the 'double-alphabet' solution and then run not-quite-valid code until it passes, currently. A few more randomized tests would help. Other than that, good kata :) Took me a while as I was apparently unaware of the full extent to the weirdness of JS's sorting algorithm.
Description Example backtick backtick backtick "js" would be "javascript". I've changed that. Won't matter until translations come into play; "js" works for syntax highlighting but not for language specific blocks.
Random argument generation could benefit from some Test library functions, notably randomToken and randomize. You can find these under Docs -> Kata Test Framework -> JS/CoffeeScript Test Reference. That doesn't mention assertDeepEquals and assertApproxEquals, but they work comparably to assertEquals.
If and when you have to pass Objects (including Arrays) as arguments, be careful to pass copies, unless you want user to be able to change the argument and have the reference solution work on the changed argument. Not an issue with primitives (Strings, Numbers, Booleans), unless passed as an Object (which is exceedingly rare).
Strict mode is mostly about bad use cases of context (this).
If you have to worry about automatic semicolon insertion then... go study about it and know what the actual ASI rules are? Because not even adding semicolons to every line will help you against some wrong programs due to how ASI work.
cough Java cough
I don't get why they don't just incorporate this into JavaScript. JavaScript's basic sort function is inexcusably stupid.
It would still be possible to hardcode the 'double-alphabet' solution and then run not-quite-valid code until it passes, currently. A few more randomized tests would help. Other than that, good kata :) Took me a while as I was apparently unaware of the full extent to the weirdness of JS's sorting algorithm.
Couple observations for the future:
Test
library functions, notablyrandomToken
andrandomize
. You can find these under Docs -> Kata Test Framework -> JS/CoffeeScript Test Reference. That doesn't mentionassertDeepEquals
andassertApproxEquals
, but they work comparably toassertEquals
.Object
s (includingArray
s) as arguments, be careful to pass copies, unless you want user to be able to change the argument and have the reference solution work on the changed argument. Not an issue with primitives (String
s,Number
s,Boolean
s), unless passed as anObject
(which is exceedingly rare).Yep, works. :]
One random test is enough really, but having 50 is essentially free with a
for
loop.Strict mode is mostly about bad use cases of context (
this
).If you have to worry about automatic semicolon insertion then... go study about it and know what the actual ASI rules are? Because not even adding semicolons to every line will help you against some wrong programs due to how ASI work.
http://inimino.org/~inimino/blog/javascript_semicolons