Reverse a String - Javascript DSA Interview Question #javascript #DSA #javascriptinterview

preview_player
Показать описание
How to do Reverse a string in Javascript using recursion - Data Structures and Algorithms Interview Question for Frontend Interviews
Рекомендации по теме
Комментарии
Автор

It may be more optimized but higher JS payload size compared to the array approach.

brokeloser
Автор

Recursive functions is never considered as optimised approach

xtraszone
Автор

We can convert string to array then reverse it and then again convert it into string like following

gauravmasalkar
Автор

Using pointer and using while loop we can solve this right?
By swapping, which will reduce memory space as well

sachintendulkar
Автор

Me: Simple for loop with string length, just decrease the count 😂😂😂

SK_Covers
Автор

What if string is null. It will throw error

kartikxisk
Автор

Sir are you using computer glass or a power glass?

IllIIIIIIllll
Автор

Good one but not optimised use one loop for this o(n)

officialpage
Автор

So why does the code stope running when it reaches “Olleh” why doesn’t it just run forever I don’t understand

terminator
Автор

function Arr(val){
if(val===''){
return '';
}else{
return
}
}

console.log(Arr('hello'))

it showing maximum call stack size exceed

venkatsai
Автор

Bro it won't work...there is no possibility for str as empty string...how it is working at your side...

venkateshp
Автор

It's pointless to use all these methods. Readalibilty is poor.

Just run a for loop in reverse.

let newStr= ' ';
for (let i = str.length -1; i>=0;i--){
newStr += str[i];
}


return newStr;



Very simple way. Why trying all this?

armorkinggaming
Автор

This is overcomplicating something very simple. Even if you had 10mil characters in one string and passed it into this function it would make such a minimal difference

LeagueJeffreyG
Автор

Brother i have typed the same code but it gave the o/p like --> Maximum call stack size exceeded....why ????

k.balamugundanbala
Автор

Don't ever write code like this. No company would accept this code in a pull request. It's very difficult to understand what it's doing

keeganfargher