如何反转包含复杂表情符号的字符串?
2022-08-30 01:22:18
输入:
Hello world
If you're able to, use the _.split()
function provided by lodash. From version 4.0 onwards, _.split()
is capable of splitting unicode emojis.
Using the native .reverse().join('')
to reverse the 'characters' should work just fine with emojis containing zero-width joiners
function reverse(txt) { return _.split(txt, '').reverse().join(''); }
const text = 'Hello world