문제 링크 : Check If a Word Occurs As a Prefix of Any Word in a Sentence
/**
* @param {string} sentence
* @param {string} searchWord
* @return {number}
*/
var isPrefixOfWord = function(sentence, searchWord) {
let arr = sentence.split(' ')
for(let i=0; i<arr.length; i++) {
if(arr[i].indexOf(searchWord) === 0) return i+1
}
return -1
};
/**
* @param {string} sentence
* @param {string} searchWord
* @return {number}
*/
var isPrefixOfWord = function(sentence, searchWord) {
const words = sentence.split(' ');
for(let i=0;i<words.length;i++){
if(words[i].startsWith(searchWord))
return i+1
}
return -1
};