28. Implement strStr()

Implement strStr().

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

思路:采用js中的indexOf方法就可以了。

/**
 * @param {string} haystack
 * @param {string} needle
 * @return {number}
 */
var strStr = function(haystack, needle) {
    var number=haystack.indexOf(needle);
    return number;
};

  

posted on 2016-05-01 13:25  baiyuhong  阅读(111)  评论(0)    收藏  举报