Skip to content

String.prototype.includes() #204

@lechang-zhang

Description

@lechang-zhang

实现一个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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions