SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with Function reverse Words(str_arg)

    I need a function reverseWords(str_arg) –it will return a string containing the words of the string str_arg in reverse order. For example, if reverseChars("The quick brown fox jumps over the lazy dog") is called, the return value will be "dog lazy the over jumps fox brown quick The".

    Can anyone help me, pls?

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,895
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    Code javascript:
    function reverseWords(str) {
      return str.split(' ').reverse().join(' ');
    }

    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thnx for quick response)! And what i have to do after? Sorry, I'm totally beginner...

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    As you're also looking for a sentence-case function elsewhere, am I right to presume that you're taking a programming course that involves these things?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, this is correct.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    While we happily help people here learn about how to improve their scripting, when it comes to educational courses there are people here who get upset at "doing your own homework" so to speak.

    If you haven't received enough information from your tutor/lecturer/teacher, you really should approach them first about the information that you need to complete your assignment.

    All the best with your studies.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,445
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by supreme_oleg View Post
    Yes, this is correct.
    Be warned! I have seen threads where students asked for answers and because they didn't show what code they had written so far for themselves, other more knowledgeable members provided solutions that worked but were so advanced it would be obvious to a teacher that the student copy/pasted instead of making an effort to learn.

    Mean? Look at it this way, if you don't at least try to learn, it's not fair to others and it's not fair to you. No one is going to be there handing you code when it's test time. If someone gives you code that gets you in trouble it will teach you a lesson you need to learn.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •