题目:
    实现 strStr() 函数。
    给你两个字符串 haystack 和 needle ,请你在 haystack 字符串中找出 needle 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回 -1 。

    1. functionstrStr(haystack: string, needle: string): number {
    2. if (!needle) return0;
    3. constlength=needle.length;
    4. letstart=0;
    5. letend=start+length-1;
    6. while (end<=haystack.length) {
    7. if (
    8. haystack[start] ===needle[0] &&
    9. haystack.slice(start, start+length) ===needle
    10. ) {
    11. returnstart;
    12. }
    13. start+=1;
    14. end=start+length-1;
    15. }
    16. return -1;
    17. }