Obsessed with React and teaching. I help people become Frontend Developers. Living with my fiancee and Yorkshire Terrier 🐶 in Poland.
- We created
reverseStringfunction which accepts a
- Then, we're calling
.reverse()built-in array method (it doesn't exist on string type 😭), ["a", "b", "c"] -> ["c", "b", "a"].
- After that we're combining array items (letters) using
.join()array method with
""argument to avoid commas into our final reversed string, ["c", "b", "a"] -> "cba".
- I still chose the one-liner solution as it looks clean - declarative code is more important than the performant one unless performance really hits. 😅
THE GUIDE TO BEAT FRONTEND INTERVIEW
Let's build a community that will help each other.