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.
This is covered by the following part of the description:
To expand:
patternMatch
is supposed to use[matchesSymbol]
on whatever it's given, and with its logic written that way you then need to define[matchesSymbol]
properties on built-in prototypes for it to behave correctly. Technically you could just defineObject.prototype[matchesSymbol]
, but it wouldn't be a very good way to do it.The test you mentioned does look incorrect to me, but I can't reproduce the issue or figure out how it might have happened.
I've re-validated my own solution a few times with no issues, so if you are getting a lot of randomised test failures it is probably an issue with your solution.
This comment is hidden because it contains spoiler information about the solution
toString
isn't considered and isn't supposed to have an effect on anything, butvalueOf
matters and is hinted at by the description at one point.This should be covered by the primitive tests.
What this is saying is that there is no special handling for a non-existent property and it should be treated the same as if it existed but had an undefined value. Sometimes things behave differently based on that, i.e. in some cases, if we have the following code:
Some things will treat
objA
andobjB
differently, even thoughobjA.prop
andobjB.prop
are bothundefined
. We don't want any special handling here, so the patterns{ prop: undefined }
and{ prop: () => true }
should match bothobjA
andobjB
.Possibly the confusion here is because that test is checking for
[matchesSymbol]
onNumber
(a function) and notNumber.prototype
.As with Symbols, Sets are supposed to be compared with
===
. The__name
thing is used by the tests for display purposes, it isn't supposed to be accessed by the solution.Technically every comparison is specified - anything that isn't explicitly covered in the description is supposed to use the fallback logic at the bottom of the Details section (i.e. basically
===
).The idea is that a symbol is the better approach because it guarantees there will be no name conflicts (i.e. things don't break if we have a user-defined type with a
matches
method that does something different, ormatches
gets added to theRegExp
object and doesn't do what we want it to). Understanding of more advanced JavaScript concepts is intended to be part of the kata's challenge.It enables it because it allows you to implement it. It's providing a hook for custom pattern matching behavior - if one doesn't exist then you can't define your own pattern matching logic for your own types.
I mean, the class implements [matchesSymbol], so it will work. :)
IIRC I originally wrote it that way, but then I realized basically everyone will build something that isn't extensible, which wouldn't be ideal. I redefined everything in terms of
[matchesSymbol]
so that a passing solution has to be extensible.Technically the
[matchesSymbol]
handling could be required only for custom stuff, but I think it's better if everything is consistent.The hope is that it can be figured out by looking at the bullet points in the Details section. If you treat the Details section as a technical spec/strange form of pseudocode, you should find that it actually spells out most of a working solution for you.
It's at least one. I'll update the description to clarify. EDIT: Done.
See above point about the Details section being like a technical spec - you should find that "match" always has the same meaning throughout, i.e. in this case it's expecting you to recursively apply the full matching logic.
The idea is that there is no distinction - a pattern is always a value.
Back to the point about Details being like a spec - "X matches Y" terms always have the same meaning, i.e. it's "<pattern> matches <input>".
It makes things more concise and brings the "syntax" in line with what you find for pattern matching in a lot of other languages. It's a pre-defined variable so your solution shouldn't need to do anything about it.
Because of these random tests, I don't think I'll be able to fully get them all to pass. There's usually only a few, but the number varies from run to run, so I'd only be getting lucky if I did pass it all. And when I look into the cases that don't pass, I don't think they're quite right by the looks of it.
So... it's a shame--I've sunk a few hours into this challenge, and it was pretty interesting. But I guess this is where I stop. ;/
It seems some of the tests have patterns that are simple objects, with set "matches" methods. Presumably we're meant to just call whatever the object's "matches" method is--regardless of where it has come from. I think that's how I'm doing it, but it wasn't clear to be from the description that how it must work.
It's explicitly saying you must set such methods on the prototypes. But that's not even necessary if you're just calling the method on the value you're given. So again, just a bit muddled with the potential of overlooking or misreading it.
I was given this by the randomised tests:
But I think it's incorrect. The pattern is expecting an array of 3 items:
The input is an array containing 3 items:
...Right?
This comment is hidden because it contains spoiler information about the solution
Or even String objects with a set .toString method which messes things up, for example? Not sure how you want such things handled though.
Loading more items...