Fundamentals
Strings
using recursion
using recursion
// const reverseStr = str => [...str].reverse().join(''); <-- weak smh function reverseStr(str) { if (!str) return ''; return reverseStr(str.slice(1)) + str.charAt(0); } console.log(reverseStr('hello world'));
- // const reverseStr = str => [...str].reverse().join(''); <-- weak smh
function reverseStr(str){let reversedstr = '';stringArr = str.split('');stringArr.forEach(function(char, index) {reversedstr = char + reversedstr;})return reversedstr;- function reverseStr(str) {
- if (!str) return '';
- return reverseStr(str.slice(1)) + str.charAt(0);
- }
- console.log(reverseStr('hello world'));