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 comment is hidden because it contains spoiler information about the solution
@hobovsky You make a good point, and I don't disagree, but I think the bigger issue is that katas, much like Science experiments, should have as much of a controlled environment as possible to ensure the user can focus on the variable of solving the problem and not figuring out an error unrelated to the problem. Not that this isn't a good lesson for the user to learn, it's just not the focus of the kata and should be avoided. If part of the training was ensuring the user wasn't using
for...in
for this reason then yes, this would absolutely be user error.Also, the kata should be held to a higher standard than the user's code, so the
Array.prototype.shuffle
addition is an error with the kata (IMO).You are correct, as stated in the Stackoverflow link.
for..in
should be avoided for this reason as should adding properties to built-in Object prototypes.[javascript] 'shuffle' exposed as index on arrays.
For users having this issue:
The quick fix for this in your code is to change your
for..in
loops to this:For Kata Author:
In test cases, this is getting added to the
Array
object's prototype:Array.prototype.shuffle=function(){...}
As a result,
'shuffle'
gets added as an "index" infor..in
loops.Example:
This will inadvertently cause an error in a user's solution who are using a
for..in
loop in their solution.In general, it's best to avoid modifying the prototype of built-in objects. Instead just create a standalone shuffle helper function, or if you absolutely need to add it to the Array prototype, use the
Object.defineProperty
method:Relevant Stackoverflow: https://stackoverflow.com/a/948379/354317
Also, in the instructions here:
This reader exposes only one method : getChunk()
Returns the following fragment of text from the file it is reading
Returns a string of random size
Returns at least one char
Returns an empty string when finished
I would just get rid of "Returns at least one char" Maybe just have this:
This reader exposes only one method : getChunk()
Returns a fragment of text from the file it is reading as a string.
The fragment can be any length, including
0
(empty string).If the fragment is an empty string, the reader has reached the end of the file, and will only return an empty string on subsequent calls.
I think I understand why it says it will return at least one char, but I think it means to say, "if doesn't return an empty string, the string will be a minimum of 1 char" which is kind of redundant info and confusing.
but what about this test case:
From the instructions:
In the instructions, it states that the
getChunk
function exposed by the reader "Returns at least one char".One of the test cases, the first chunk received by the parse method is an empty string (so the entire string it was reading must be an empty string), thus making the charCount, wordCount, and lineCount expected to be 0.
Even if it was allowed that the first string received by
getChunk
was an empty string, there are other tests where there are empty lines that count as a line, so wouldn't an empty string test case still have alineCount
of 1?Example:
and if that's the case, then shouldn't this be true:
I've not written a Kata before, but I'd see if you could import the user's code as a module instead of adding the
solution.txt
file inline to theindex.js
file. Then a user couldn't circumvent the testing like this.Is there a way to undo the solution/points? I feel dirty.
This comment is hidden because it contains spoiler information about the solution
![I am not a smart man](http://e.lvme.me/gj224xt.jpg = 220x200)
@xDranik, makes sense now. I confused sets with intervals. Regardless of the type of interval (closed, half-closed, etc...) the interval would still be the same. Sorry if I confused anyone further on this.
@OverZealous, thanks for the visuals.
Thanks for the clarification. So in determining if the value of
x
is within the interval[1, 5]
, I could express that mathematically as1 <= x < 5
.I feel like the instructions could be more clear on this rather than having to extrapolate whether the first and/or last number are included in the interval.
"
[1, 5]
is an interval from 1 to 4. The length of this interval is 4." This would be better because if someone asks you to count "from 1 to 5", you would undoubtedly count: 1, 2, 3, 4, 5.Edit:
This kind of interval is referred to as a "half-closed interval". In interval notation, it would be written as
[a, b)
. Which I think would make for a slightly more compelling Kata. Instead of having an array of arrays, have an array of interval notations in the form of strings.Anyways, fun Kata. Could be slightly more clear. Would be interested to see a remake of this Kata using interval notation rather than a 2d array.
This comment is hidden because it contains spoiler information about the solution
I did read the description/instructions in their entirety before voting and I'm saying I don't understand from the description how to achieve the intended solution. I understand that I'm supposed to create a 2D array based on the
townSize
parameter passed in. I then understand that I'm supposed to snake (traverse) through the 2D array depositing an incremented value that shows the path taken through the 2D array. I understand that a-1
means to go left/up,0
means to go left or right/up or down, and1
means to go right/down (street/avenue).I don't understand where I'm supposed to start in the 2D array or if it's assumed that I have to start at index
[0, 0]
. I don't understand how the values in thestreets
andavenues
parameters relate to my current position in thetown
. For example, given your examplecompute(3, streets, avenues)
, how do I know to start at index[0, 0]
(where I would deposit a value of1
) and move right? From your instructions, a1
would allow me to move right and a0
would allow me to move left or right.I'm not trying to be mean, I'm trying to be helpful and understand your kata. The first step would be to learn how to edit the kata. The next step would be to ensure that the return value of the compute function will pass your Test expectations. Your first test expects
[[1,2,3],[6,5,4],[7,8,9]]
as a return value. If I write this inside the compute function:return [[1,2,3],[6,5,4],[7,8,9]];
, the kata still fails. I tried wrapping it in a string and also tried stringifying it with JSON, which neither worked. So I believe you have issues with your Test fixture comparing array values. I pointed this out in my previous comment and how to solve that because as it stands, this is what happens:Test Failed: Expected: [[1,2,3],[6,5,4],[7,8,9]], instead got: [[1,2,3],[6,5,4],[7,8,9]]
So it's an interesting concept for a kata but I don't think it's ready.
Loading more items...