Solved

Reverse sentense

Posted on 2012-04-08
8
152 Views
Last Modified: 2012-06-21
I was wondering using JavaScript how would you reverse this sentence

my name is kevin

so it would say

Kevin is name my
0
Comment
Question by:stargateatlantis
[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
  • 5
  • 3
8 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37822181
"my name is kevin".split(" ").reverse().join(" ")
0
 

Author Comment

by:stargateatlantis
ID: 37826182
How would you do it without using split reverse join
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37826292
hmmm, why?

there are a bazillion ways you could do it. Like this for example (not using split, reverse or join):

var split = "my name is kevin".match(/([^\s]+)/g), reversed = ""; while(split.length) reversed += split.pop() + " "; alert(reversed);

Open in new window

0
Industry Leaders: 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!

 

Author Comment

by:stargateatlantis
ID: 37827030
sorry I know I was looking for a for loop solution
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37827143
why loop in javascript when you can loop in native code?

is this homework?
0
 

Author Comment

by:stargateatlantis
ID: 37827191
Its homework.  Wouldn't it be faster to use a loop?
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37827257
nope
0
 
LVL 23

Accepted Solution

by:
basicinstinct earned 500 total points
ID: 37830258
ok, how about this, you want to reverse a sentence using looping in js. it is homework, so i can't just give you the answer. since you are obviously studying programming you should be able to make a start... you tell me where you are stuck and i'll help you...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

751 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