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 really don't remember what this was about, but are you referring to this?
Because I think that must have been added to the description after I had written the comment.
I can kinda see how
has
always seems to be used on a base object whilehaving
is used further down an expression chain (although this seems to be a distinction without any meaningful difference).But
with
is brought up in the description without there being any significant difference betweenwith
andhaving
:What makes
with(1).pupil
the correct syntax for that expression vs.having(1).pupil
? As far as I can tell they mean exactly the same thing.The kata was probably changed to add numbers in addition to alphabetic characters.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
(JS)
Since
has
,having
, andwith
are synonyms, any of the following should be permitted, and should have the same result:As far as I can tell, only
having
is tested, and in factwith
is a JS keyword so it's likely to cause problems for many solutions.This comment is hidden because it contains spoiler information about the solution
The suggestion was to break it into several katas that gradually build up to this (I even gave examples of them, so it really shouldn't be confusing).
But it's been 5 years since I suggested that, so you feel free to just not do it.
Probably a few hours, but it was a long time ago, so I really don't remember.
Yeah, passing an object with key-value pairs would be the easiest (and proper) way to give a function "named arguments". I.e., you'd change the function from
function fnname(arg1, arg2)
tofunction fnname({arg1, arg2})
, and change the code that calls it fromfnname(val1, val2)
tofnname({arg1: val1, arg2: val2})
.However, the kata challenge here was to hotfix a pre-existing function that takes ordinary arguments, so it implies that you can't or aren't supposed to modify the function... you're just supposed to wrap it in a new anonymous function that figures out what arguments it expects and provides defaults.
My first go at it wasn't efficient enough, but I came up with a faster algorithm. Now it runs in <4 seconds for all of the tests (Javascript).
Sure, now solve that kata without using
__proto__
(which is a non-standard, internal object that you shouldn't ever use) orObject.create
(whichnew
predates;new
cannot be syntactic sugar for something that didn't even exist yet).new
is the correct method of doing this.I actually wish you'd go into more detail on this:
I'm pretty certain it's not an accurate statement, but I'd like to know why you say it is.
I'm pretty sure that is incorrect. You have to use "new" in order to get an
ArrayComprehension
object that has theArrayComprehension.prototype
methods that were created. The description clearly indicates that it should return anArrayComprehension
object, and the preloaded solution shows that you're supposed to defineArrayComprehension.prototype
methods, which won't work unless it is.Either the person calling the function has to do it (correct), or it doesn't (WRONG) -- then you have to stick at the top of the constructor a patch that detects this error and fixes it:
...but either way, you have to use "new". The proper place to use it is when calling
ArrayComprehension
to create a new instance of it. Skipping "new" and then patching the constructor function to detect and fix this omission is not a best practice. It will encourage sloppy coding and lead to coders who don't understand what "new" does.Using "new" when calling the constructor is best practice, and is what should be encouraged. It's not just convenient syntactic sugar; it actually creates a new object. If you use "new", the
this
object inside the constructor function will be that new object; if you don't use "new",this
will not be a new object. And to create an object that will test asinstanceof ArrayComprehension
, the only correct way to do it is usingnew ArrayComprehension
. You shouldn't use__proto__
to hack it.If I'm forgetting something here, give me specific examples of what you're talking about.
It looks like someone edited the description to something very similar to what you posted.
Loading more items...