5Mi / wumi_blog

for recording improvimg my experience
21 stars 0 forks source link

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

Open 5Mi opened 8 years ago

5Mi commented 8 years ago

EMC

5Mi commented 8 years ago

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

/**
 * 递归匹配是否存在 家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 '';
        }
    }
}

这篇关于递归