I would like to create a JS function that takes two arguments: an Object and a property. If the object has the given property, then the function should remove it from the object, and return true.
This is as far as I've got, but it keeps returning false on test cases. I believe because the 'obj.prop' part is not catching properly - but not sure why.
Any help would be much appreciated!
function removeProperty(obj, prop) {
if ( obj.prop ) {
delete obj.prop;
return true;
} else {
return false;
}
}