-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday13.js
More file actions
35 lines (26 loc) · 1.06 KB
/
day13.js
File metadata and controls
35 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* Emojify!
Popular services like Slack and Github allow for emoji shortscodes, meaning
they will detect when a word in a sentence begins and ends with a colon (:)
and automatically replace that word with an emoji.
These shortcodes allow users to add an emoji to their messages by typing a
code rather than searching for an emoji from a list.
For example, typing :smile: will replace that text with 😊
*/
const emojis = {
"smile": "😊",
"angry": "😠",
"party": "🎉",
"heart": "💜",
"cat": "🐱",
"dog": "🐕"
}
const emojifyWord = (word) => {
const formattedWord = word.startsWith(':') && word.endsWith(':') ? word.slice(1,-1) : word
return emojis[formattedWord] ? emojis[formattedWord] : formattedWord
}
const emojifyPhrase = (phrase) => phrase.split(' ').map((word) => emojifyWord(word)).join(' ')
console.log(emojifyWord(":heart:"));
console.log(emojifyWord(":flower:"));
console.log(emojifyWord("elephant"));
console.log(emojifyPhrase("I :heart: my :cat:"));
console.log(emojifyPhrase("I :heart: my :elephant:"));