DEV Community

Discussion on: Interview Qs Decoded - # 2

Collapse
 
jpantunes profile image
JP Antunes

Using recursion so that only half the string is looped over:

const strReverso = ([...str], i = 0) => {
    return i < str.length / 2
            ? ([ str[i], str[str.length - 1 - i] ] = [ str[str.length - 1 - i], str[i] ], strReverso(str, ++i))
            : str.join('');
}