Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2022
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let students = JSON.parse(input);
  4.  
  5. let htmlText = ['<table>'];
  6.  
  7. let objNames = students[0];
  8.  
  9. htmlText.push(`${'<tr><th>'}${Object.keys(objNames).join('</th><th>')}${'</th></tr>'}`);
  10.  
  11.  
  12. for (const obj of students) {
  13.  
  14. htmlText.push(`${'<tr><td>'}${Object.values(obj).join('</td><td>')}${'</td></tr>'}`);
  15. }
  16.  
  17.  
  18. htmlText.push('</table>');
  19.  
  20. console.log(htmlText.join('\r\n'));
  21.  
  22. }
  23.  
  24. solve(`[{"Name":"Stamat",
  25. "Score":5.5},
  26. {"Name":"Rumen",
  27. "Score":6}]`);
  28.  
  29. solve(`[{"Name":"Pesho",
  30. "Score":4,
  31. " Grade":8},
  32. {"Name":"Gosho",
  33. "Score":5,
  34. " Grade":8},
  35. {"Name":"Angel",
  36. "Score":5.50,
  37. " Grade":10}]`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement