Sunny-117/js-challenges

String.prototype.includes()

lechang-zhang opened this issue · 0 comments

实现一个string的includes方法

String.prototype.myIncludes = function (word) {
    let str = this;
    if (word === '') return true;
    for (let i = 0; i < str.length - word.length + 1; i++) {
        let subStr = '';
        for (let j = i; j < i + word.length; j++) {
            subStr += str[j];
            if (subStr === word) return true;
        }
    }
    return false;
}