Day 21 of 100 Days Of Code
Day 21: August 14, Tuesday
Today ‘s Progress: I continue work Intermediate Algorithm Scripting.
Thoughts: Don’t have much time tonight, only worked through two challenges. I started a third but didn’t finish it.
console.log("Convert HTML Entities");
//Convert the characters &, <, >, " (double quote), and ' (apostrophe), in a string to their corresponding HTML entities. (You got to be kidding me!!!)
function convertHTML(str) {
const htmlEnt={
'&':'&',
'<':'<',
'>':'>',
'\"':'"',
'\'':"'"
};
return str.split('').map(function(ojbect){//Use Split and map function to filter str.
return htmlEnt[ojbect] || ojbect;
}).join('');//Use .join prototype
};
//test here
console.log(convertHTML("Dolce & Gabbana")); //should return Dolce & Gabbana.
console.log(convertHTML("Hamburgers < Pizza < Tacos")); //should return Hamburgers < Pizza < Tacos.
console.log(convertHTML("Sixty > twelve")); //should return Sixty > twelve.
console.log(convertHTML('Stuff in "quotation marks"')); //should return Stuff in "quotation marks".
console.log(convertHTML("Schindler's List")); //should return Schindler's List.
console.log(convertHTML("<>")); //should return <>.
console.log(convertHTML("abc")); //should return abc.
console.log("<----------------------next exercise------------------------->");
This one used elements from previous Challenges.
Link(s) to work
- Started Intermediate Algorithm Scripting.
Introduction to the Functional Programming Challenges
- PassedSorted Union
- PassedConvert HTML Entities All code is in GitHub and repl.it here: repl.it IntermediateAlgorithmScripting.js or GitHub IntermediateAlgorithmScripting.js
Written on August 14, 2018