计算单词jquery中的字符

时间:2013-06-15 21:57:13

标签: javascript jquery

如何用jQuery计算单词中的字符?

function count(word, character)
{
   return ???;
}

例如:

count('atesta', 'a'); // should return 2
count('testaaa', 'a'); // should return 3

1 个答案:

答案 0 :(得分:3)

为什么一切都必须在jQuery中?

function count(haystack, needle) {
    return haystack.split(needle).length-1;
}
相关问题