Advertisement
-Annie-

JSONTable

Jun 10th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let output = '<table>\n';
  3.  
  4.     for(let i = 0; i < input.length; i++) {
  5.         let tokens = input[i].split(',');
  6.         let nameSplit = tokens[0].split(':')[1];
  7.         let name = nameSplit.slice(1, nameSplit.length - 1)
  8.         let positionSplit = tokens[1].split(':')[1];
  9.         let position = positionSplit.slice(1, positionSplit.length - 1)
  10.         let salarySplit = tokens[2].split(':')[1];
  11.         let salary = salarySplit.slice(0, salarySplit.length - 1)
  12.  
  13.         let person = {
  14.             name: name,
  15.             position: position,
  16.             salary: salary
  17.         };
  18.  
  19.         output += '    <tr>\n';
  20.         output += (`         <td>${person.name}</td>\n         <td>${person.position}</td>\n         <td>${person.salary}</td>\n    <tr>\n`);
  21.     }
  22.  
  23.     output += '</table>';
  24.     console.log(output);
  25. }
  26.  
  27. solve(['{"name":"Pesho","position":"Promenliva","salary":100000}',
  28. '{"name":"Teo","position":"Lecturer","salary":1000}']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement