Warning
This code is very bad and unsafe, don't use it.
A simple file to use a few functions and a custom Array based on primitive data types.
This file allows you to easily create a conditional array where you can run an internal function that will return the first value whose correspondent condition returns true.
To add to your project place the script tag before your own script.
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/carlin978/boolArray@main/boolArray.min.js"></script>
var <name> = new BoolArray(<values>);
The values should be formatted with the following function:
cBoolObj(<condition>,<value>);
and it should return this: {bool:<condition>,value:<value>}
You might want to shorten the cBoolObj()
function which you can do like this:
var <shortened name> = cBoolObj;
The syntax would look something like this:
var <name> = new BoolArray(cBoolObj(<condition>,<value>),...);
The end result should look something like this:
var blArray = new BoolArray(cBoolObj("myVar<5",12),cBoolObj("myVar>=5",16));
The push function will test the validity the parameter and, if valid, push it to the array.
<name>.push(cBoolObj(<condition>,<value>));
The log function will return a formatted string representing the array ready to be logged to the console.
console.log(<name>.log());
The pop function will remove the last element of the array.
<name>.pop();
The shift function will remove the first element of the array.
<name>.shift();
The reverse function will reverse the array.
<name>.reverse();
The run function will iterate the array and it will return the first value whose correspondent condition returns true.
<name>.run();
Note: You have to save the value somewhere. Example:
var <varname> = <name>.run();