logo

NJP

Reverse a string in javascript - fastest execution

Import · Jan 04, 2021 · video

hi everyone in this video i'm going to demonstrate you how we can reverse a string in javascript using the reduce function so the implementation using the reduce function is considered superior when we talk about the fastest execution state in comparison to the one using the reverse function in javascript and the one using the for loop in javascript so let me just get started with the coding part i have already declared a thing named sunday and created a prototype for a function so in here i am simply going to return there is a string by using string dot split and then i'm going to call the reduce function which in turn also uses two parameters called accumulator and the current value and then i can simply sum up both of them and now when i call this function over here it gives me the reverse string so here is my reverse string so we can also test this with a sentence and it's a sentence is today is sunday and still the string is reversed and there's one more method which we can incorporate over here as we have done for using the reverse function so i'm going to do the same over here first let me change the name of the function call and i am going to use the spread operator so as i told you already that if i'm using a spread operator i don't need split function okay so if i place the function call over here i still get the same result so thank you for watching guys and stay safe and stay healthy

View original source

https://www.youtube.com/watch?v=rHqbO6FXElk