?
Solved

Need help with manipulating paragraph

Posted on 2014-09-23
3
Medium Priority
?
164 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

752 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