Forked from anonymous/bonfire-convert-html-entities.js
Created
December 9, 2015 12:36
-
-
Save patrickcurl/fcb8385c3f674d0b56ab to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/patrickcurl 's solution for Bonfire: Convert HTML Entities
This file contains hidden or 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: @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] = "<"; | |
} | |
if(x === '"'){ | |
arr[y] = """; | |
} | |
if(x === "'"){ | |
arr[y] = "'"; | |
} | |
}); | |
return arr.join(""); | |
} | |
convert("Dolce & Gabbana"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment