Skip to content

Instantly share code, notes, and snippets.

@harshitanand
Created December 4, 2015 08:56
Show Gist options
  • Save harshitanand/50ea353c60763d8f009b to your computer and use it in GitHub Desktop.
Save harshitanand/50ea353c60763d8f009b to your computer and use it in GitHub Desktop.
// Bonfire: Convert HTML Entities
// Author: @harshitanand
// Challenge: http://www.freecodecamp.com/challenges/bonfire-convert-html-entities
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function convert(str) {
// :)
str = str.replace(/[&|<|>|'|"]/gi, function(a) {
switch (a) {
case '&':
return '&amp;';
case '<':
return '&lt;';
case '>':
return '&gt;';
case "'":
return "&apos;";
case '"':
return '&quot;';
}
});
return str;
}
convert('Dolce & Gabbana');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment