已知一个数组a,其中存在空字符串,去除空字符串后,截取一段生成数

2019-01-23  本文已影响0人  microcosm_c162

function isAdjoin(a, b) {

            const aStr = a.join('-');

            const bStr = b.join('-');

            // es5

            // if (aStr.indexOf(bStr) > -1) {

            //     return true; // 相邻

            // }

            // return  false; // 不相邻

            // es6

            return aStr.includes(bStr);

        }

        const c1 = ['', 1, 2, 3, 4, 5], d1 = [3, 4];

              c2 = ['', 1, 2, 3, '', 4, 5], d2 = [3, 4];

        console.log(isAdjoin(c1, d1)); // true

        console.log(isAdjoin(c2, d2)); // false

        // 参考资料 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/includes

上一篇下一篇

猜你喜欢

热点阅读