MZ (SOLVED) Check for Any Numbers Between Range within an array?

Hey everyone!
I just made a custom evented Cooking Game, where the player can choose up to 8 items to put together to cook.
I do this by setting each Item chosen's ID# to 8 CookSlot variables, then I then put all 8 variables together in an array.

So far, everything's working out great!

BUT

I've run into an issue where I need to check this array of 8 values for any numbers in a specific range, but don't know how to do so.

For example:
all the meat items are ID# 51-59
and all the fish are ID# 61-69
and all the mushrooms are ID# 71-79
etc

So, I figured an easy way to check if the player's Ingredients array contained any fish, is to check if any values in the array contain a number between 60 and 70(because all fish items are between those numbers).
Then I can trigger a switch 'contains fish?' to ON or something.

Problem is, I can't seem to find an easy way of doing this!

-I can check if ONE value is inside the array with a conditional:
JavaScript:
$gameVariables.value(ArrayVarId).includes(61)

-And I can check if multiple values are inside an array:
JavaScript:
$gameVariables.value(ArrayVarId).includes(61) && $gameVariables.value(ArrayVarId).includes(62) && $gameVariables.value(ArrayVarId).includes(63) etc -it gets way too long aaaa

^^But I can't figure out how to check if there's a number that falls between a specific range of numbers!
--
I've been looking around, and dug up some other ways people have done similar things, for example:

#1
JavaScript:
var year = parseInt($gameVariables.value(1).match(/\d{4}/)[0]);
$gameVariables.setValue(2, (year>=1920 && year <= 2020) ? year : 0);

(Explanation: It retrieves text from variable 1, extracts the first match of a four-digit number, and store it in variable 2.
Note that if it's not within range, it will return 0.)

-but I'm not sure how to get that to work with an array 🙁
=========================
#2
@caethyril also had something neat here as well:

JavaScript:
const v = $gameVariables.value(1); [2,3,4,5].every(id => v >= $gameVariables.value(id))

(Explanation: "true iff the values of game variables 2, 3, 4, and 5 are all < the value of game variable 1".)

^^This one looks really promising, but again, not sure how to apply that to an array!

Can this be done? Can you search an entire array for any numbers between a certain range?

If I don't come up with something it'll get messy, because there's quite a few ranges I'll need to check, fish was just one example. (ie, check ranges to see if Contains: 'Fruit/Vegetables/Mushrooms/Berries/Spices/Dairy' etc!
I would create a plugin that creates a new array function for you to use.

Code:
/*:
 * @plugindesc Adds an easy function to check if any item in an array falls within a range of numbers
 * @author Gensun
 * @help
 * Example:
 * $gameVariables.value(ArrayVarId).hasRange(51, 59);
 */

Array.prototype.hasRange = function(lowerBounds, upperBounds) {
    for (var i = 0; i < this.length; i++) {
        if (lowerBounds <= this[i] && this[i] <= upperBounds) return true;
    }
    return false;
}
Save the text above as a .js and install it as a plugin. You can now use $gameVariables.value(ArrayVarId).hasRange(51, 59) to check if an item contains a meat item
EDIT: added a plugin header so it's more user-friendly

P.S. Use whatever method feels most intuitive. The suggestion below should work but is harder for me to wrap my head around its syntax.
Assuming that $gameVariables.value(ArrayVarId) is an array that contains the 8 item IDs, you could do it like this:
JavaScript:
$gameVariables.value(ArrayVarId).some(x => x >= 61 && x <= 69);
That would return true if a fish ID is in the array.
Save the text above as a .js and install it as a plugin. You can now use $gameVariables.value(ArrayVarId).hasRange(51, 59) to check if an item contains a meat item
EDIT: added a plugin header so it's more user-friendly

P.S. Use whatever method feels most intuitive. The suggestion below should work but is harder for me to wrap my head around its syntax.
This is fantastic and is absolutely a plugin worth saving!
Thank you so much for your incredible work! T-T

Assuming that $gameVariables.value(ArrayVarId) is an array that contains the 8 item IDs, you could do it like this:
JavaScript:
$gameVariables.value(ArrayVarId).some(x => x >= 61 && x <= 69);
That would return true if a fish ID is in the array.
Wow! so the answer was .some? that's really cool! I had gotten so used to only knowing how to barely use .includes 😅
It also looks real similar to when people do the '$gameVariables.value(VarID) > 60 && $gameVariables.value(VarID) < 70' thing,
but I'm seeing like 3 'x' used in there which I haven't seen before...

Both of these solutions are perfect!
Thank you so much for all your help, Gensun and Arthran! Especially so close to after the holiday!!
but I'm seeing like 3 'x' used in there which I haven't seen before...
@Arthran's x is just a variable. Y'know, like when you did grade school math x = 2+3

It could be called anything, it's just a reference for the current element of the array that the function is being performed on.

Since you mentioned a regex-based example, this is how you'd use that in this instance:

JavaScript:
$gameVariables.value(id).some(x => /6[1-9]/.test(x.toString()))
@Arthran's x is just a variable. Y'know, like when you did grade school math x = 2+3

It could be called anything, it's just a reference for the current element of the array that the function is being performed on.

Wow, that's really eye-opening!
And the tutorial link is really helpful too!
Since you mentioned a regex-based example, this is how you'd use that in this instance:

JavaScript:
$gameVariables.value(id).some(x => /6[1-9]/.test(x.toString()))
So many different ways to accomplish things!! 😮‍💨


-Thanks to everyone's wonderful efforts, I hope that maybe all the wonderful info can help another dev out in the future!
With that I will mark this to be solved.
This thread is being closed due to being solved. If you need it reopened, report it to let us know why. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/solved-check-for-any-numbers-between-range-within-an-array.164388/