function builtInReverse(string) {
return string.split('').reverse().join('');
}
function forLoopReverse(string) {
let newString = '';
for (let i = string.length - 1; i >= 0; i--) {
newString += string[i];
}
return newString
}
function recursionReverse(string) {
return string === '' ? string : recursionReverse(string.substr(1)) + string.charAt(0);
}
function reverseString(string, handler) {
return handler(string);
}
console.log( reverseString('test', builtInReverse) ); // 'tset'
console.log( reverseString('test', forLoopReverse) ); // 'tset'
console.log( reverseString('test', recursionReverse) ); // 'tset'