Exception
Exception

Reputation: 8389

Logging the results of this function

Somebody please explain me this code in detail

function reverse(s){
   return s.split("").reverse().join("");
}

Upvotes: 0

Views: 44

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039398

The function takes a string, it splits it in its constituent characters to obtain an array using the split function, it reverses this array using the reverse method and joins the elements with an empty string.

Basically it reverses a string which given the name of the function I guess doesn't come as a surprise to anyone.

So:

reverse('abc')

will return:

cba

Upvotes: 1

Related Questions