An Interest In:
Web News this Week
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
August 25, 2021 10:02 pm GMT
Original Link: https://dev.to/frontendengineer/technical-interview-1-reverse-a-string-33pb
Technical Interview 2: Reverse a string
Interview Question #1:
Write a function that reverses a string.
If you need practice, try to solve this on your own. I have included 3 potential solutions below.
Note: There are many other potential solutions to this problem.
Solution #1: Array methods
function reverseString(str) { return str.split("").reverse().join("");}
Solution #2: array forEach
function reverseString(str) { let reversedString = '' str.split('').forEach(char => { reversedString = char + reversedString }) return reversedString}
Solution #3: array reduce
function reverseString(str) { return str.split('') .reduce((prev, curr) => curr + prev, '')}
In case you like a video instead of bunch of code
Happy coding and good luck if you are interviewing!
Original Link: https://dev.to/frontendengineer/technical-interview-1-reverse-a-string-33pb
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To