Reverse sentense

I was wondering using JavaScript how would you reverse this sentence

my name is kevin

so it would say

Kevin is name my
stargateatlantisAsked:
Who is Participating?
 
basicinstinctCommented:
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
 
basicinstinctCommented:
"my name is kevin".split(" ").reverse().join(" ")
0
 
stargateatlantisAuthor Commented:
How would you do it without using split reverse join
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
basicinstinctCommented:
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
 
stargateatlantisAuthor Commented:
sorry I know I was looking for a for loop solution
0
 
basicinstinctCommented:
why loop in javascript when you can loop in native code?

is this homework?
0
 
stargateatlantisAuthor Commented:
Its homework.  Wouldn't it be faster to use a loop?
0
 
basicinstinctCommented:
nope
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.