超出最大调用堆栈(递归)

时间:2017-01-06 19:02:57

标签: javascript recursion

我让自己感到困惑,我无法摆脱这个最大的调用堆栈错误。

假装box变量大100倍。我只是为了示范而缩减了。我不知道为什么这样做,我仔细检查了我的代码十亿次并尝试了许多不同的方式

let terminals_010617 = `YMMU6072258 Y773
YMMU6082317 Y773
YMMU6125912 Y773
YMMU6136250 Y773
YMMU6149895 Y773
YMMU6154464 Y309
ZCSU2601485 H798
ZCSU2656908 H798
`;





const REGEX = (function () {

    const RAW_CONTAINER_SEARCH = function (string) {

        let reg_newline = /\n/gi;  //       ---- USE THIS
        //let reg2 = /[a-zA-Z0-9]{0,}\n/gi; // off for temporary --- needs more testing

        let container_house = []; // will house the container+terminals

        let index_traveler;  // traverses between container+terminals ----  will first hold END of slice value, then BEGINNING of next
        let index_traveler2; // 
        let condition;

        container_house.push(string.slice(0, string.search(reg_newline))); // initiates the first container + terminal
        string = string.slice(string.search(reg_newline), string.length); // new string is after slice index

        GET_ALL_CONTAINERS();
        function GET_ALL_CONTAINERS() {
            condition = reg_newline.test(string);  // boolean
            index_traveler = 0
            index_traveler2 = string.search(reg_newline); // this will grab fresh index of index_traveler every loop

            while (string.length > 200) {
                container_house.push(string.slice(index_traveler, index_traveler2)) // grab container + terminal
                string = string.slice(index_traveler, string.length);
                GET_ALL_CONTAINERS();

                if (!condition) {
                    break;
                }

            }


        }
        console.log(container_house);
    }


    const ADD_TO_WL = function () {
        console.log('hello');
    }


    return {
        search_raw_containers: function (string) {
            RAW_CONTAINER_SEARCH(string);
        },
        add_to_wl: function (containerArray) {
            ADD_TO_WL(containerArray);
        }
    }

}());


REGEX.search_raw_containers(terminals_010617);

0 个答案:

没有答案
相关问题