[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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