Solved

Need help with manipulating paragraph

Posted on 2014-09-23
3
151 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now