Advertisement
WindFell

Score To HTML

Sep 4th, 2018
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.     String.prototype.htmlEscape = function(){
  4.         return this.replace(/&/g, '&')
  5.             .replace(/</g, '&lt;')
  6.             .replace(/>/g, '&gt;')
  7.             .replace(/"/g, '&quot;')
  8.             .replace(/'/g, '&#39;');
  9.     };
  10.  
  11.     let result = "<table>\n  <tr><th>name</th><th>score</th></tr>\n";
  12.     let table = JSON.parse(input);
  13.  
  14.     for (let record of table) {
  15.         result += `  <tr><td>${record.name.htmlEscape()}</td><td>${record.score}</td></tr>\n`;
  16.     }
  17.  
  18.     result += "</table>";
  19.     return result;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement