Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

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
0
stargateatlantis
Asked:
stargateatlantis
  • 5
  • 3
1 Solution
 
basicinstinctCommented:
"my name is kevin".split(" ").reverse().join(" ")
0
 
stargateatlantisAuthor Commented:
How would you do it without using split reverse join
0
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now