Is there a way to consolidate this code into one function that can handle all the tasks below?
I'm adding more text here to meet the requirements and hoping for a solution. Thank you! TypeScript is an amazing language that differs slightly from JavaScript. I tried my own method to resolve the issue below, but kept getting 'undefined'. It's challenging to group, target, and change the values.
class foods {
private apple: boolean;
private banana: boolean;
private guava: boolean;
private passionfruit: boolean;
private melon: boolean;
private oranges: boolean;
private porkchop: boolean;
private steak: boolean;
private chicken: boolean;
toggleFruit(fruit: string) {
for (let key in this) {
if (this.hasOwnProperty(key)) {
this[key] = false;
}
}
this[fruit] = true;
}
}