Last active
November 16, 2022 10:23
-
-
Save abu-hasib/89875a0cce90b3b8bdc26ae5e08c6767 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function inventory() { | |
return { | |
items: [], | |
add: function(item) { | |
if(this.items.includes(item)) { | |
return | |
} | |
this.items.push(item); | |
}, | |
remove: function(item) { | |
if (this.items.includes(item)) { | |
let index = this.items.indexOf(item) | |
if (index > -1) { | |
this.items.splice(index, 1) | |
} | |
} | |
}, | |
getList: function() { | |
return this.items | |
} | |
} | |
} |
How we call the remove function here?
Thanks for this solution, really helped
// make object
const a = new inventory();
// Add item
a.add('zohaib');
// view List
a.items; OR a.getList();
// Remove Item
a.remove('zohaib');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much. I had an idea of solving it this way but didn't really know how to write the code.
If you don't mind, how do you approach problem solving?