reverse('apple') //--> elppa
reverse('hello') //--> olleh
reverse('Greetings!') //--> !sgniteerG
My Solution(s)
function reverse(str) {
return str.split('').reduce((result, char) => {
return character + reversed;
}, '')
}
// as one-liner:
const reverse = (str) => str.split('').reduce((result, char) => char + result, '');
SG Solution 1 (w/ reverse()
)
function reverse(str) {
return str.split('').reverse().join('');
}
SG Solution 2 (w/o reverse()
)
function reverse(str) {
let reversed = '';
for (const character of str) {
reversed = character + reversed;
}
return reversed;
}