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.
coding GOD
gave me headache
This comment is hidden because it contains spoiler information about the solution
Number of occurences
and
Find the matching parenthesis
have the same problem (especially the latter where extending the prototype doesnt make much sense)
I suggest to change it in all languages to acheieve consistency! This also applies to several katas whereby a method of a class is used instead of a standalone function.
I personally do not care about invalidating solutions to an easy kata if this would mean improving user experience with the kata. I think that improvements in consistency, maintainability, user experience, and overall quality are worth invalidating solutions en masse, because I think it causes no negative impact neither on users, nor on the kata in question.
But in this case I thought that only JS requests for prototype extension and other languages use free functions. Now Chrono explained it's not the case, so I am not sure if it's worth changing in JS, or in all languages.
we could make this backwards compatible as well, to avoid invalidating 60,000+ solutions, but on the other hand new solvers will be confused when seeing the solutions page
Ruby, Swift and TypeScript at least.
I am seriously tempted to get rid of the prototype extension and make the solution just a free function. It causes more trouble than it's worth, and there are also other kata which can teach how to do extensions.
Do any other languages follow the pattern of extending a string type?
Fork
Object.defineProperty
not to teach bad practice (extending a built-in is already bad practice, but too late for that...)** added some indications in the initial code
** checks that the user indeed extends the prototype (in case the user erases the initial code and rewrites a normal function)
first point:
When the compiler encounters a function call for which it does not find a function declaration, it assumes the function has this prototype:
int func_name ()
.strdup()
is sadly not yet part of standard C (it will be added in C23). This is why the compiler does not find it in<string.h>
: it is a POSIX extension. you have to#define _GNU_SOURCE
before#include <string.h>
to make it visible:second point: your code is almost correct, but has 2 mistakes:
what would be the point of passing
jaden_case
in parameter if you were expected to return a fresh new string ? you must write to it, as indicated in the initial code, not reassign it, which is not visible by the caller.(also note that you forgot to allocate a byte for the
'\0'
terminator here)how could this be the case then?
expected 'How Can Mirrors Be Real If Our Ey Aren\'t Real' to equal 'How Can Mirrors Be Real If Our Eyes Aren\'t Real'
How is Ey supposed to end up being Eyes, very random out of nowwhere
No, and please read the posts below or provide some proof when you say something is broken:
Your code is wrong.
broken on Javascript