7 kyu
Add a property to an object
663 of 664Palle
Loading description...
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.
You might want to add edge cases where the
property
is inherited through the prototype chain. This will invalidate solutions that usein
operator because it searches through the prototype chain as well.No random tests.
The subject of this test is not mentioned anywhere.
This comment has been hidden.
Maybe you should add a test for a falsey value, as in, obj[prop] = 0 or obj[prop] = false. As of now solutions which check for truth of obj[property] instead of existence of property pass too.
Thank you for the suggestion. I have added a test for adding a property with a false value.
But it still works. What you would need to do is check if the function can distinguish between no property and false property. What you are doing now is just asking the function to add a false property. You need to ask the function to change a property which is already set as false. In that case, while the wrong function(the one which uses obj[prop]) will change the value, the right function will throw an error because the property exists.
So, something like:
OK. I think I've got it right now. Thank you.
Preloaded solution has wrong arguments: it has
addProperty(name, into)
instead ofaddProperty(into, name, value)
as specified by the tests.Thank you. I have updated the kata.