Last active
December 19, 2015 08:49
-
-
Save alanerzhao/5928113 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function strSearch(defaultStr,searchStr){ | |
var arr = [], | |
i = 0, | |
num = 0; | |
length = defaultStr.length; | |
for(i; i<length; i++) { | |
//查找字符 | |
if(defaultStr.indexOf(searchStr,i) != -1) { | |
num++; | |
i = defaultStr.indexOf(searchStr,i); | |
arr.push(i); | |
} | |
} | |
return { | |
num :"你查找的"+searchStr+"次数为:"+num, | |
arr : "出现的位置:"+arr | |
}; | |
} | |
console.log(strSearch("sdasadasd","s")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment