Solved

Need help with manipulating paragraph

Posted on 2014-09-23
3
162 Views
Last Modified: 2014-10-24
a.      countWordsBeginningWith: this method should return the amount of words that begin with an inputted string. The optional second parameter (integer representing the sentence) should determine what sentence the words come from when present.
b.      getWordsSorted: this method should return a sorted list of words. The first parameter should be the sorting function used to sort words (length, alphabetization, and reverse alphabetization), the optional second parameter should determine the sentence to pull words from (integer representing the sentence).

var sampleData = 'My experience in the nature study area was full of surprises. First of all, many unexpected creatures crossed our path! For example, as soon as we left the parking area and entered the grassy path, a long snake slithered along the edge of the high grass and quickly disappeared. In addition, I was surprised by how colorful the grasses, which from a distance all appear to be green, actually are.';

a. sample output 1:  countWordsBeginningWith('ex') ---> experience, example
a. sample output 2:  countWordsBeginningWith('ex',1) ---> experience

b. sample output 1:  getWordsSorted('length') ---> list of longest to shortest
b. sample output 1:  getWordsSorted('length',1) ---> list of longest to shortest in first sentence only
0
Comment
Question by:894359
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40341073
a) sampleData.match(/\bex[\w]*\b/gim) will return the following array : ["experience", "example"]
I believe you just need to use(return)
       getSentences(n-1).match(/\bex[\w]*\b/gim); to return experience where n is the optional second parameter (integer representing the sentence)

b) getSentences(n-1).getWords().sort(function(word1, word2) { return word1.length > word2.length });

https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Array/sort
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question