-
Notifications
You must be signed in to change notification settings - Fork 34
/
15-fun-with-emoji.js
17 lines (14 loc) · 904 Bytes
/
15-fun-with-emoji.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Minutes of Javascript #14 - Fun with Emoji!
// See: https://playcode.io/651693/
// Interesting features of Emoji and Javascript
// It’s possible to spread emoji sequences into their single parts
console.info([...'👩👩👧👦']); // returns ['👩', '', '👩', '', '👧', '','👦', '']
console.info([...'👨👧👧']); // returns [ '👨', '', '👧', '', '👧' ]
console.info([...'👨❤️💋👨']) // ['👨', '', '❤', '️', '', '💋', '', '👨']
// You can also combine Emoji
console.info(["👨", "", "👩", "", "👧"].reduce((prev, curr) => prev + curr)) // returns "👨👩👧"
// Zero-width joiner (ZWJ) "\u200d" acts as the glue between Emoji
function combineEmoji(arr) {
return arr.reduce((a,b) => a + '\u200d' + b);
}
console.info(combineEmoji(['🏳','🌈'])); // returns "🏳🌈"