Reverse String Portion with JavaScript

💻 JavaScript Interview Question You will be given a string and two indexes (a and b). Your task is to reverse the portion of that string between those two indices inclusive. str = "javascript", a = 1, b = 5 --> "jcsavaript" East right ? But rather than traversing the string and using 2-pointer technique, you have to use the inbuilt functions of javascript. This tests your understanding of the language and how it works internally. function solve(st, a, b){ return st.slice(0,a)+(st.slice(a, b+1).split("").reverse().join(""))+st.slice(b+1); } Feel free to discuss more in comments 🖐 #javaScript #CodingInterview #WebDevelopment #Frontend #React

To view or add a comment, sign in

Explore content categories