Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Reverse a String

Data Structures, Operators & Stringseasy

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 128: Working With Strings - Part 1

Implement `reverse(str)` returning the characters of `str` in reverse order.

Sample tests

Input: reverse("hello")
Output: "olleh"
Input: reverse("")
Output: ""

+ 2 hidden tests run on Submit.

Hints

Common pitfalls
  • This splits by code unit, so it can mangle characters outside the basic plane (emoji).

Learning resources

  • MDN: String.prototype.split
Approach & explanation (try first)

Splitting to an array lets you reverse and rejoin into the reversed string.

Loading...
⌘/Ctrl + Enter

Run your code to see results.