Created
December 4, 2015 08:56
-
-
Save harshitanand/50ea353c60763d8f009b to your computer and use it in GitHub Desktop.
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
// 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 '&'; | |
case '<': | |
return '<'; | |
case '>': | |
return '>'; | |
case "'": | |
return "'"; | |
case '"': | |
return '"'; | |
} | |
}); | |
return str; | |
} | |
convert('Dolce & Gabbana'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment