Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I have updated the translation. I updated the casing, but I kept using
gearBox
since the kata description for csharp has it as two words. I added an additional test case to check forif
and?;
. I also updated the description to not mention extension methods for the javascript version and for the return value to benull
instead of-1
.This is a cool kata and I think a JS translation is worthwhile. A few pieces of feedback before approval:
Identifiers should be
camelCased
- e.g. dot property access down the entire chain should becar.engine.gearbox.numberOfGears
. Note particularly that "gearbox" is a single word and so the camel-cased version isgearbox
, notgearBox
. The functionGetNumberOfGears(car)
should be camel-cased, and thecar
parameter is superfluous and should be removed.As per the guidelines,
therefore there should be a test which enforces no "if" or ternary operators in the solution. This can probably be achieved by just banning the strings
'if'
and':'
.Tidy up the description so that for JavaScript it just doesn't mention "extension methods" at all. You already have the language conditional rendering in place for the next paragraph, so just merge the two and reword.
I also suggest that we use
null
as the return value rather than-1
when the property is not found. The use of-1
is sometimes understandable in statically typed languages where we perhaps want to avoid nullability, but in dynamic JS with the additional explicit semantics ofundefined
andnull
I don't think using a particular number as a marker to represent "null-ish" is justified. This particular piece of feedback is optional; your choice as to what you want to do.I need an approval for this translation. It's an old kata, but I thought the material matched very well for javascript too.
I was asked this question in my own interview for my current job 5 years ago. I liked it so much I decided to make Katas from the memorable ones.
I don't know if this is clever or a best practice. I just wasn't aware that you could do this with template literals.
Now, as to what is a best practice?
I don't think it is a best practice to support outdated browsers. Not everyone wants or can afford to support everything under the sun. The kata is run on node, and if what you are using supports the option, then it is fair game.
Where does it go thru the array twice?
After
.map
it's a join. Is that considered to be going thru the array?I am glad others are saying it was difficult too!! I totally underestimated it!
I used to think this kind of code was unreadable before too, but I have gotten used to it. I would however prefer better variable names.
I don't know that this exact implementation is a popular problem (restricting the user to these particular indices), but it's a version of the two-sum problem which is a well-known problem. I wouldn't really consider what you did cheating, by the way ;)
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
I would only call this super simple if you are well versed in regular expressions. To me, it might as well be in French.
This comment is hidden because it contains spoiler information about the solution
Took me a while to get this answer. While it is very clever, I don't see how this is anywhere close to a best practice.
Loading more items...