Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <meta charset="utf-8"/>
- <body></body>
- <script>
- // Create a new unattached HTML element
- // and optionally set its innerText property
- function el(type,text) {
- if (text) {
- const e = el(type);
- e.innerText = String(text);
- return e;
- }
- return document.createElement(type);
- }
- // Create a new unattached button element
- function button(title) {
- return el('button', title);
- }
- // Main routine
- ;(function() {
- // Table containing multiple rows and 2 columns per row
- const table = [
- ['b', 'ill'],
- ['j', 'ill'],
- ['f', 'ill'],
- ['st', 'ill'],
- ['c', 'at'],
- ['b', 'at'],
- ['r', 'at'],
- ['s', 'at'],
- ];
- // Dictionary of unique items
- const dictionary = new Set();
- // Iterate the rows of the table
- table.forEach(row=>{
- // Add each item to the dictionary
- // (this eliminates repeats)
- dictionary.add(row[1].toUpperCase());
- });
- // For each unique dictionary item
- dictionary.forEach(item=>{
- // Create a button whose text contains the item
- const btn = button(item);
- // Append the button to the HTML document's body element
- document.body.appendChild(btn);
- });
- })();
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement