a function which returns the string malena backwards in javascript

index.tsx
function reverseString(str) {
  return str.split("").reverse().join("");
}

reverseString("malena"); // Outputs: "anelam"
122 chars
6 lines

The reverseString function takes a string as an argument (str). It then uses the split("") method to split the string into an array of characters. The reverse() method is called on the array to reverse the order of the characters. Finally, the join("") method is used to join the characters back together into a string. The reversed string is returned as the output of the function.

In this case, when we call reverseString("malena") it will output "anelam", which is the string "malena" backwards.

related categories

gistlibby LogSnag