I am making some chemistry game as a Telegram bot in JavaScript where you have an inventory and you need to mix the right chemicals. I have the inventory contained in an array, and in order to prevent brute-forcing your way to a level by simply pasting your inventory, I need to check if the user input contains the needed chemicals exclusively, and not any of the others in the array.
For example:
users[id].inventory = ["Beaker", "Water", "Baking soda", "Heating plate", "Hydrochloric acid"];
if (users[id].level === 1 &&
msg.text.toLowerCase().indexOf('baking soda') !== -1 &&
msg.text.toLowerCase().indexOf('hydrochloric acid') !== -1 &&
msg.text.toLowerCase().indexOf('beaker') === -1 &&
msg.text.toLowerCase().indexOf('water') === -1 &&
msg.text.toLowerCase().indexOf('heating plate') === -1) {
msg.answer("You mix some baking soda with hydrochloric acid.\nSome fun fizzing happens and you produce useless CO2 gas.");
}
At higer levels you will get a much larger inventory and this will lead to very large if-statements this way. This looks bad and there must be a better way. Is there such thing like an exclusive indexOf() or any other solution? I have checked out arr.filter() for example but I can't find out a good way to implement this.