JenMorgan / js-learning

0 stars 0 forks source link

Write a JavaScript function to check whether an object contains given property #27

Open kartamyshev opened 4 years ago

kartamyshev commented 4 years ago

Example:

const user = {
  name: 'Julia',
  age: 27
};

contains(user, 'name'); // true
contains(user, 'abc'); // false
JenMorgan commented 4 years ago
const student = {
    name : "David Rayy",
    sclass : "VI",
    rollno : 12 
  };

function checkTheProp (obj, prop) {
    let key = prop;
    return (key in obj);
}
JenMorgan commented 4 years ago
describe ("CheckTheProp ", function() {
    it("should return true if the object contains given property", function() {
        assert.equal(checkTheProp(student, "name"), true);
    });

    it("should return false if the object does not contain the property", function() {
        assert.equal(checkTheProp(student, "adress"), false);
    });
});