Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String.prototype.includes() #204

Open
lechang-zhang opened this issue Nov 3, 2022 · 0 comments
Open

String.prototype.includes() #204

lechang-zhang opened this issue Nov 3, 2022 · 0 comments

Comments

@lechang-zhang
Copy link
Contributor

实现一个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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant