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
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);
Comments
Leave a comment