DEV Community

Discussion on: Daily Challenge #37 - Name Swap

Collapse
 
deleteman123 profile image
Fernando Doglio

You mean like this? It would work for your use case, although I don't know how you want to handle things like having more than 2 names or last names?

function nameShuffler(name) {
  return name.split(" ").reverse().join(" ")
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jmulans profile image
Ju 🔗

And with arrow function

const nameShuffler = string => string.split(' ').reverse().join(' ')
Collapse
 
deleteman123 profile image
Fernando Doglio

Yeap, a quick, little fun one liner. I love it!