If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

It is unclear how you are measuring density- 2 is 8 and a third percent of 24, but the density should take into account the size of your keyword,
so if you did match This is a day and 'this is the day', perhaps the density would be 33 and a third percent, since yoy are using eight words out of twenty four.

Code:

function densewords(keyword, text){
var m1= text.match(/\b[a-zA-Z']+\b/g).length,
m2= text.match(RegExp('\\b'+keyword+'\\b', 'gi')).length,
m3= keyword.split(' ').length;
return (100*(m2*m3/m1)).toFixed(2)+ '%';
}
var k= "[tT]his is a|the day", m1, m2, percent,
t= "This is a day that is really important for us so this is the day we are waiting for a long time now something.";
densewords(k, t)