Code4Wars / codewars

0 stars 1 forks source link

Recursive reverse string #6

Open hellocan opened 8 years ago

hellocan commented 8 years ago

Your objective is to complete a recursive function reverse() that receives str as String and returns the same string in reverse order

Rules: reverse function should be executed only N times. N = length of the input string helper functions are not allowed changing the signature of the function is not allowed Examples: reverse("hello world") = "dlrow olleh" (N = 11) reverse("abcd") = "dcba" (N = 4) reverse("12345") = "54321" (N = 5)

where By http://www.codewars.com/kata/536a9f94021a76ef0f00052f/train/javascript

hellocan commented 8 years ago
function reverse(str) {
    var len = str.length;
    arr = str.split('');
    for (var i = 0; i < len / 2; i++) {
        t = arr[len - i - 1];
        arr[len - i - 1] = arr[i];
        arr[i] = t;

    }
    return arr.join("")
}
Chrono79 commented 6 years ago

That code doesn't use recursion.