Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. <style>
  2. .result {
  3. width: 35px;
  4. height: 35px;
  5. }
  6.  
  7. .col-header, .row-header {
  8. font-weight: bold;
  9. }
  10.  
  11. .col-header {
  12. text-align: center;
  13. }
  14.  
  15. .row-header {
  16. text-align: right;
  17. }
  18.  
  19. .dark {
  20. background-color: #EEE;
  21. }
  22.  
  23. .result.true.dark {
  24. background-color: #0D0;
  25. }
  26.  
  27. .result.true.light {
  28. background-color: #0F0;
  29. }
  30.  
  31. .result.false.dark {
  32. background-color: #D00;
  33. }
  34.  
  35. .result.false.light {
  36. background-color: #F00;
  37. }
  38.  
  39. </style>
  40.  
  41. <script>
  42. var totest = [true, false, 1, 0, -1, "1", "0", "-1", "", "javascript", null,
  43. undefined, [], {}, [[]], [0], [1], parseFloat("nan")];
  44.  
  45. function map(f, x) {
  46. var result = [];
  47. for (var i = 0; i < x.length; i += 1)
  48. result.push(f(x[i]));
  49. return result;
  50. }
  51.  
  52. function repr(x) {
  53. if (typeof(x) === "string")
  54. return '"' + x.replace('"', '\\"') + '"';
  55.  
  56. if (x && x.constructor === Array)
  57. return "[" + map(repr, x).join(", ") + "]";
  58.  
  59. if (x && typeof(x) === "object")
  60. return "{}";
  61.  
  62. return String(x);
  63. }
  64.  
  65. function rowcolcls(i, j) {
  66. return (i % 2)? "dark" : "light";
  67. }
  68.  
  69. function buildTable() {
  70. var tableHtml = ["<table><tr><td></td>"];
  71. for (var i = 0; i < totest.length; i += 1) {
  72. tableHtml.push("<td class='col-header " + rowcolcls(0, i) + "'>");
  73. tableHtml.push(repr(totest[i]));
  74. tableHtml.push("</td>");
  75. }
  76. tableHtml.push("</tr>");
  77.  
  78. for (var i = 0; i < totest.length; i += 1) {
  79. tableHtml.push("<tr><td class='row-header " + rowcolcls(i, j) + "'>");
  80. tableHtml.push(repr(totest[i]));
  81. tableHtml.push("</td>");
  82. for (var j = 0; j < totest.length; j += 1) {
  83. var result = totest[i] == totest[j];
  84. tableHtml.push("<td class='result " + result + " " + rowcolcls(i, j) + "'></td>");
  85. }
  86. tableHtml.push("</tr>");
  87. }
  88. tableHtml.push("</table>");
  89. return tableHtml.join("");
  90. }
  91.  
  92. document.write(buildTable());
  93. </script>
Add Comment
Please, Sign In to add comment