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
Solved

Need help with manipulating paragraph

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I enable / disable a text box with a checkbox 3 23
JS does not refresh 6 30
Start Auto-download of File when page loads? 1 20
html border input line 7 13
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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 …
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…

809 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