how to get array of sentences and words passing as parameter to a function in javascript? -


i have function

 var init = function(data){      sentences: " have sentences , return array containing sentences"      words : "this method should return array of words in ‘data’ when there no parameter passed in. optionally, when there parameter passed in number, return words in sentence indicated input parameter"       reverse sentences: "this method same sentences, except should return sentences in reverse order"       reverse words :" same words in reverse order"      countwordsbeginningwith:" method should return amount of words begin inputted string. optional second parameter should determine sentence words come when present." 

thanks

i think need decompose argument (assuming it's string) array. instance:

function getallwords(sentences) {     var result = sentences.split(' ');     return result; }  var init = function(data){     var result = [];     result['words'] = getallwords(data.text);     // result['sentences'] = getallsentences(data.text);     // result['sentencesreversed'] = getreversesentences(data.text);     // result['sentencewords'] = getreversewords(data.text);     // result['beginswith'] = getwordsbeginningwith(data.text, data.beginswith);     return result; }  var getit = {     'beginswith': 't',     'text': 'this stuff. sentence. stuff happens now.' };  console.log(init(getit)); 

this simplistic answer, not taking account periods, commas, , other bits. that's general answer. for loops and/or regex's may occur after point, buyer beware.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -