Reputation: 8389
Somebody please explain me this code in detail
function reverse(s){
return s.split("").reverse().join("");
}
Upvotes: 0
Views: 44
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 join
s 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