SOURCE

let arr = ['r>128','r<255','b>20','a>b']; // 条件数组
let color = [129,25,32,36] // 像素点各通道值
function getBoolean(color,arr) {
    let result = true;
    const getPixelIndex = (item) =>{
        switch(item){
            case 'r':
                return 0
                break;
            case 'g':
                return 1
                break;
            case 'b':
                return 2
                break;
            case 'a':
                return 3
                break;
        }
    }
    const isNumber = (value) => {
        return /^\d+$/.test(value);
    }
    const getValue = (pixel_item, target) => {
        if (isNumber(target)) {
            return Number(target)
        } else {
            return pixel_item[getPixelIndex(target)]
        }
    }
    let count = 0
    arr.find(item => {
        count++
        switch (item[1]){
            case '>':
            (item.slice(2))
            result = color[getPixelIndex(item[0])] > getValue(color, item.slice(2))
            break;
            case '<':
            result = color[getPixelIndex(item[0])] < getValue(color, item.slice(2))
            break;
            case '=':
            result = color[getPixelIndex(item[0])] == getValue(color, item.slice(2))
            break;
        }
        console.log('待判断次数:'+ arr.length+' 已判断次数:'+count)
        return !result
    })
    // console.log(result)
    return result
}
const bool = getBoolean(color,arr)
console.log('最终结果',bool)
console 命令行工具 X clear

                    
>
console