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.
The sentence "as a set of strings" has been added to the description. This is enough?
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.
The title is "Wait. What?". Yeah I expected people to get confused. This isn't really a puzzle either.
It's a bit harder in TypeScript but I can't put in any hints without completely spelling out the answer. I can add something that says vaguely says "you need to troubleshoot this thing" but I didn't think I needed to.
@wthit56 I want people to see that error message though. I want that to be part of the troubleshooting process. The error message practically tells you what to do.
This comment is hidden because it contains spoiler information about the solution
Loading more items...