wumi_blog icon indicating copy to clipboard operation
wumi_blog copied to clipboard

EMC 部分记录的问题,与解决

Open 5Mi opened this issue 8 years ago • 1 comments

EMC

5Mi avatar Jun 30 '16 14:06 5Mi

就是想把今天项目写的放在这儿-_-#

/**
 * 递归匹配是否存在 家1
 * @param addressArr
 * @param index
 * @returns {string}
 */
async function recursiveFindHome(addressArr, index) {
    let text_first = '家';
    index = index || 1;
    let pattern = '^' + text_first + index + '$'
    let re = new RegExp(pattern);
    let hadescription = addressArr.find((address) => {
        return re.test(address.addressDescription);
    })
    //没匹配到返回undefined
    if (!hadescription) {
        let description = text_first + index;
        return description;
    } else {
        /*要有出口防止堆栈溢出*/
        if (index < 99) {
            index += 1;
            /*递归时要把函数 return出去*/
            return recursiveFindHome(addressArr, index);
        } else {
            console.log('not?')
            return '';
        }
    }
}

这篇关于递归

5Mi avatar Nov 09 '16 09:11 5Mi