Santas Emoji Hack!
During Christmas, Santa wants to ban negative emojis, so when people use negative emoji shortcodes, he wants positive emojis to appear instead.
In other words, 😠 should result in 🎁 instead of 😠.
-
Write a function that checks if a lowercase word starts and ends with a colon. If it does, check if it exists in the hackedEmojis object, and replace it with the corresponding emoji. If not, return the original word.
- Example input: ":cry:"
- Example output: 😄
-
Write a function to find any emoji shortcodes in a phrase. Use your emojify function from the previous exercise!
- Example input: "Just read your article 👎"
- Example output: "Just read your article 👏"
Don't just replace the shortcodes, but also any emojis are added directly to the text.
function emojifyWord(word) {
if (word.startsWith(":") && word.endsWith(":")) {
const emojiKey = word.slice(1, -1)
if (emojiKey in hackedEmojis) {
return hackedEmojis[emojiKey]
}
}
return word
}
function emojifyPhrase(phrase) {
const wordArr = phrase.split(" ")
const modifiedPhrase = wordArr.map(word => {
return emojifyWord(word)
}).join(" ")
return modifiedPhrase
}
📚 startsWith() by MDN
📚 in by MDN
📚 split() by MDN