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.
Unpublishing due to many long-standing issues.
Linked list is a duplicate to a million existing katas.
Tests are incredibly weak: most tests only involve at most 2 nodes. And there are no random tests.
There are two kinds of
to_a
in the tests: the instance methodto_a
and the class methodto_a
. They're redundant.There's nothing to stop us from implementing
reverse
by converting it to array, reversing it as an array, then converting it back.And then suddenly you're putting in a
Range
object intofrom_a
? Isn't the meaning offrom_a
, well, do something from an array? What's aRange
doing here? By this rate I wouldn't be surprised if we'd have to supportString
s andEnumerator
s as well.Did you really think through the requirements when you made this kata? Because it's obvious you don't, you just slap together a bunch of stuff about linked lists and expect people to contemplate into what you were thinking about when writing the tests.
Besides, you didn't really write up any kind of documentation. If you've done that you should've already seen through most of the problems mentioned above.
Needs sample tests
It's not clear how the
String
representation of aNode
object is supporsed to look:one #=> <Node @name=1, @next=nil>
two #=> <Node @name=2, @next=<Node @name=1 @next=nil>>
Note, how this is inconsistent: For the second case I'd expect a comma between the value of the
@name
and ```@nextIn other words:
two #=> <Node @name=2, @next=<Node @name=1, @next=nil>>````How about fixing this by having the comma in both cases (in fact all cases -- in case of a longer list)?
Depending on how detailed the test for the this kata are, it can be confusing for users to fail because of this, without adding to the point of the kata (which is understanding a singly linked list).
I, too, really liked this kata and going back to the basics to implement a simple data structure. The couple of comments I have are as follows:
from_a
method actually needs to handle ranges and arrays.reverse
,from_a
,to_a
(class), andto_a
(instance)). The complete list of required methods can be gleaned from the given Text Examples, but it'd be nicer to have everything explicitly listed."Thanks to shadchnev, I broke all of the methods from the Hash class."
Thank you, Abbe! Good points. I added an extra test case line to the bottom of my description, and I now explain that you need to create 2 to_a methods, a class and instance method. Yes, it's useful to implement basic data structures from scratch, instead of depending on a library/gem. That fact that Ruby doesn't have a built-in linked list is bad for programmers but good for us learners.
OK thanks hencethus! I'll certainly keep that in mind for future katas
It's not clear from the examples in the description that to_a should be both an instance and a class method. I got stuck there for a while, since the first tests only use the class method.
I could consider making the tail parameter to the constructor optional as well, but then you'd have to explain that in your examples.
Personally, I think 'value' is a more natural name than 'name' for accessing the Node's value.
But all in all, it was a nice kata. Always good to implement some of the basic data structures from scratch once in a while.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Rayning and anhkind, for some reason I can't use the 'reply' function. Most of the solutions posted so far don't hard-code in an upper bound. Even one sieve solution generates an upper bound using the prime number theorem.
Why do you think it should be specified ahead of time?
I'm rayning3 on Skype, if you want to talk. If you have any questions about Ruby, I've been programming in it for over 1 year now. My email is rayning@gmail.com. I'm happy to help! What's your new job? Congratulations.
Loading more items...