统计jQuery中各字符串出现次数的工具

2020-05-23 06:02:24易采站长站整理

re = arr[i];
while( (resu=re.exec(source)) != null ) {
num++;
}
}
return num;
};
for (type in rObj) {
rarr = rObj[type];
if (rarr.constructor !== Array) {
rarr = [rarr];
}
num = subCount(rarr);
result.push({type: type, num: num});
}
// sort 0:次数顺序 1:次数倒序
if (typeof sortType !== ‘undefined’) {
if (sortType===0) {
func = function(a, b) {
return a.num – b.num;
};
} else if (sortType===1) {
func = function(a, b) {
return b.num – a.num;
};
}
result.sort(func);
}
callback(result);
}
function main(keywords, source, callback, sortType) {
var rObj = keywords.constructor === Array ? buildRe(keywords) : keywords;
count(rObj, source, callback, sortType);
}
var rObj = {
string: [/’string’/g, /”string”/g],
number: [/’number’/g, /”number”/g],
‘boolean’: [/’boolean’/g, /”boolean”/g],
object: [/’object’/g, /”object”/g],
‘undefined’: [/’undefined’/g, /”undefined”/g],
‘function’: [/’function’/g, /”function”/g],
‘array’: [/’array’/g, /”array”/g],
‘ready’: [/’ready’/g, /”ready”/g],
input: [/’input’/g, /”input”/g],
type: [/’type’/g, /”type”/g],
text: [/’text’/g, /”text”/g],
radio: [/’radio’/g, /”radio”/g],
checkbox: [/’checkbox’/g, /”checkbox”/g],
password: [/’password’/g, /”password”/g],
submit: [/’submit’/g, /”submit”/g],
button: [/’button’/g, /”button”/g],
id: [/’id’/g, /”id”/g],
div: [/’div’/g, /”div”/g],
body: [/’body’/g, /”body”/g],
html: [/’html’/g, /”html”/g],
HTML: [/’HTML’/g, /”HTML”/g],
parentNode: [/’parentNode’/g, /”parentNode”/g],
nextSibling: [/’nextSibling’/g, /”nextSibling”/g],
iframe: [/’iframe’/g, /”iframe”/g],
before: [/’before’/g, /”before”/g],
after: [/’after’/g, /”after”/g],
script: [/’script’/g, /”script”/g],
width: [/’width’/g, /”width”/g],
height: [/’height’/g, /”height”/g],
top: [/’top’/g, /”top”/g],
left: [/’left’/g, /”left”/g],
absolute: [/’absolute’/g, /”absolute”/g],