Find the Index of the First Occurrence in a String
- javascript
- strings
Problem URL:Find the Index of the First Occurrence in a String
My Solution
JavaScript
/**
* @param {string} haystack
* @param {string} needle
* @return {number}
*/
const strStr = (haystack, needle) => {
if (needle.length === 0) {
return 0;
}
return haystack.indexOf(needle);
};
Let's Connect
Twitter •GitHub •LinkedIn