Loading...
Engaged employer
Reverse a String in JavaScript. Show us multiple ways to do it. - Whiteboard
Anonymous
String.prototype.reverse = function(){ return this.split('').reverse().join(''); }
1. Reverse order iteration const reverseString = (str) => { let reversedStr = ''; for (let i = str.length - 1; i >= 0; i--) { reversedStr += str[i]; } return reversedStr; }; 2. Hal-index recursion const reverseString = (str) => { if (str.length < 2) { return str; } const halfIndex = Math.ceil(str.length / 2); return reverseString(str.substr(halfIndex)) + reverseString(str.substr(0, halfIndex)); };
Check out your Company Bowl for anonymous work chats.
Get actionable career advice tailored to you by joining more bowls.
Stay ahead in opportunities and insider tips by following your dream companies.
Get personalised job recommendations and updates by starting your searches.