7 kyu

Add a property to an object

663 of 664Palle
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • farhanaditya Avatar

    You might want to add edge cases where the property is inherited through the prototype chain. This will invalidate solutions that use in operator because it searches through the prototype chain as well.

  • FArekkusu Avatar

    No random tests.

  • FArekkusu Avatar

    Should work with falsy values

    The subject of this test is not mentioned anywhere.

  • donaldsebleung Avatar

    This comment has been hidden.

  • CrazyMerlyn Avatar

    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.

    • Palle Avatar

      Thank you for the suggestion. I have added a test for adding a property with a false value.

      Suggestion marked resolved by Palle 10 years ago
    • CrazyMerlyn Avatar

      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:

      obj.sleepy = false;
      Test.expectError("Did not throw expected error", function() {
        addproperty(obj, "sleepy", "anything");
      })
      
    • Palle Avatar

      OK. I think I've got it right now. Thank you.

  • Balkoth Avatar

    Preloaded solution has wrong arguments: it has addProperty(name, into) instead of addProperty(into, name, value) as specified by the tests.