How to reverse a string that contains complicated emojis?

Input:

Hello world👩‍🦰👩‍👩‍👦‍👦

Desired Output:

👩‍👩‍👦‍👦👩‍🦰dlrow olleH

I tried several approaches but none gave me correct answer.

This failed miserablly:

const text="Hello world👩‍🦰👩‍👩‍👦‍👦";

const reversed = text.split('').reverse().join('');

console.log(reversed);

This kinda works but it breaks 👩‍👩‍👦‍👦 into 4 different emojis:

const text="Hello world👩‍🦰👩‍👩‍👦‍👦";

const reversed = [...text].reverse().join('');

console.log(reversed);

I also tried every answer in this question but none of them works.

Is there a way to get the desired output?

9 Answers
9

Leave a Comment