View Single Post
Old 01-02-2013, 06:51 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,244
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Of course, there is no reason at all to even need that alphabet function.
Code:
function start ()
{
    var arrayPhrase = "Yesterday is history. Tomorrow is a mystery. But today is a gift. For this it is called present.";

    var phrases = arrayPhrase.split(".");
    var wordsPerPhrase = [ ];
    var totalWords = 0;
    for ( var p = 0; p < phrases.length - 1; ++p )
    {
        var words = phrases[p].replace(/^\s+/,"").replace(/\s+$/,"").split(" ");
        wordsPerPhrase[p] = words.length;
        totalWords += words.length;
    }
    alert (  "Total words = " + totalWords + "\n\n" 
           + "Total phrases = " + phrases.length + "\n\n" 
           + "Words in each phrase = " + wordsPerPhrase.join(", ")
          );
}
start();
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote