add: 检查单词是否为句中其他单词的前缀
This commit is contained in:
1 parent
4940ceaeb9
commit
5c5f35c535
3 files changed
+24
-1
No files matched your search
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @param {string} sentence
|
||||
* @param {string} searchWord
|
||||
* @return {number}
|
||||
*/
|
||||
export const isPrefixOfWord = function (sentence, searchWord) {
|
||||
const items = sentence.split(' ')
|
||||
|
||||
for (const n in items) {
|
||||
if (items[n].indexOf(searchWord) === 0) return Number(n) + 1
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
Reference in new issue
Block a user