Javascript String countWords(s)

Description

Javascript String countWords(s)



function countWords(s){
    s = s.replace(/(^\s*)|(\s*$)/gi,"");
    s = s.replace(/[ ]{2,}/gi," ");
    s = s.replace(/\n /,"\n");
    return s.split(" ").length;
}



PreviousNext

Related