Answer to Question #171569 in HTML/JavaScript Web Application for sairam

Question #171569

Trekking Kit


Given an object


trekkingKit in the prefilled code and item item as an input, write a JS program to add the method isKitContains to the constructor function Trekking using the prototype.


The method


isKitContains checks whether the trekkingKit contains the given item.


Quick Tip

The Object.getOwnPropertyNames() method gives an array containing the properties of the object.

Input


The input will be a single line containing a string


item


Output


The output should be a single line containing a boolean value


Sample Input 1

ruckSackBag

Sample Output 1

true


Sample Input 2

surfboard

Sample Output 2

false


1
Expert's answer
2021-03-14T12:10:15-0400
function Trekking(item) {
    this.item = item;
}

const trekkingKit = {
    ruckSackBag: ['ruck', 'sack', 'bag'],
}

Trekking.prototype.isKitContains = function(obj) {
    return Object.getOwnPropertyNames(obj).some( item => item === this.item )
}

const trekking = new Trekking('ruckSackBag');
const restTrekking = trekking.isKitContains(trekkingKit);

console.log(restTrekking);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS