Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2015 12:36
Show Gist options
  • Save anonymous/0fc95edb8a30b07c5f32 to your computer and use it in GitHub Desktop.
Save anonymous/0fc95edb8a30b07c5f32 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/patrickcurl 's solution for Bonfire: Convert HTML Entities
// Bonfire: Convert HTML Entities
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-convert-html-entities
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function convert(str) {
// :)
var arr = str.split("");
arr.forEach(function(x,y){
if(x === "&"){
arr[y] = "&";
}
if(x === ">"){
arr[y] = ">";
}
if(x === "<"){
arr[y] = "&lt;";
}
if(x === '"'){
arr[y] = "&quot;";
}
if(x === "'"){
arr[y] = "&apos;";
}
});
return arr.join("");
}
convert("Dolce & Gabbana");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment