7 kyu
Get key/value pairs as arrays
7,112 of 10,660jhoffner
Loading description...
Arrays
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This comment has been hidden.
CS:
No sample tests
No random tests
nal test case doesn't check the whole keys and values
Ruby :
function name should be in
snake_case
3.0 should be enabled
No sample tests
No random tests
All done in this fork
JS: Unlike the sample test, the final test case doesn't check the whole keys and values
This comment has been hidden.
Python translation: https://www.codewars.com/kumite/61755f4dab9a4e0045d37fc1?sel=61755f4dab9a4e0045d37fc1 Please take a look and approve it. Thanks
Ruby: no tests written for the 'Test' button
Fixed in this fork
JavaScript:
Needs randomized testingSo does ruby~~
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
.
This comment has been hidden.
Object.values
wasn't invented then. I suspect reading the fine error message would have told you this.Great little kata for someone just learning how to access keys and values!
Suggestion for ruby-kata.
Change method name from this:
keysAndValues(data)
into this:
keys_and_values(data)
Fixed in this fork
This comment has been hidden.
OP solved it, closing
how can i get all the property's name and data ? i can't solve this..is there anyone can help?
Suggestion for the description (I was kind of confused by it):
Style Points: This kata only tests for data that uses object literal notation (simple objects). For extra style, can you get your method to work for JavaScript objects that extend their prototype, and only include the object's own properties, not those of their prototype?
"own" might be giving too much away, but I thought it was clearer than e.g. "properties specific to that object, ...".
I was confused by the description as well. I thought the answer should include the inherited properties for extra style, when it actually meant the opposite.
I'm passing the first two tests, but failing the third??? WHAT IS THE THIRD TEST
WTF, the instructions told me to check for prototype keys so I did (data.hasOwnProperty(key)), but it was making me fail the third test. Once I removed that part I passed all the tests??? WHAT IS THIS BS
Can I downvote this kata?
This comment has been hidden.
You would think that JS supported
Object.values
but it doesn't :(Found this going through the Ruby Katas. Seems like this was intended for JavaScript since style points refers to JS object prototypes?
Found what?
I meant the problem as a whole. "Style Points: This kata only tests for data that uses object literal notation (simple objects). For extra style, can you get your method to check for JavaScript objects that extend their prototype?" The above refers to JavaScript prototypes so I just thought this problem was meant for JavaScript.
Ah I See. Good catch. I updated it so that it calls out the style points as being a JS/CS thing only. Ruby devs don't have these types of worries.
This comment has been hidden.
you need to return [x, y]
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Quite simple, really - you've got the keys and values backwards. You're returning this:
[[1, 2, 3], ['a', 'b', 'c']]
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Order is guaranteed since Ruby 1.9. The insertion order is retained.
KeysAndValues is not a good name for method in Ruby. It should be keys_and_values.
This comment has been hidden.
Good point. I updated the description to encourage this as an extra credit type of thing. Does the description make sense?
Yup. Might want to check your description though. You're using
#
for comments which are unsupported in JavaScript (needs to be either//
or/* */
). Also, your second and third examples are duplicates.Ah. You found a bug in the display logic. Its showing the coffeescript and ruby examples when it should be hiding them. Thanks.
Reposted as suggestion.
That should use
Test.assertSimilar(a, b, ...)
rather thanTest.expect(a == b, ...)
which will always fail for that test.I came across same katas that I've already passed. Is it a bug?
Did this happen only once or does it happen often?
On philospophical side, real martial art katas are something that get repeated thousands of times, if you are any good. I would love to see that kind of katas. E.g. for refactoring applying tranformation a,b,c & d.
A single-quote in front of b' is missing in the expected result
Thanks. Fixed.