Created
November 16, 2015 00:22
-
-
Save ArielLeslie/8d40b5c614c6d97aec05 to your computer and use it in GitHub Desktop.
Bonfire: Convert HTML Entities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convert(str) { | |
var mapping = { | |
'&' : '&', | |
':' : ':', | |
'<' : '<', | |
'>' : '>', | |
'"' : '"', | |
"'" : ''' | |
}; | |
var words =str.split(''); | |
words = words.map(function(word){ | |
return mapping.hasOwnProperty(word) ? mapping[word] : word; | |
}); | |
return words.join(''); | |
} | |
convert("Dolce & Gabbana"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment