This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const data = { | |
| Parent: ["Child 1", "Child 2", {Child3:'Sub Child'}], | |
| }; | |
| // OR | |
| const data = { | |
| Parent: { | |
| Child1: "Child 1", | |
| Child2: {Child21: "Child 21", Child22: "Child 22"}, | |
| Child3: [ | |
| "Child 31", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // evaluate expressions | |
| const createList = (items) => { | |
| // code removed for brevity | |
| case "array": | |
| items.forEach((item) => { | |
| createList(item); | |
| }); | |
| break; | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // call the function on page load | |
| window.onload = () => { | |
| createList(data); | |
| markupArray.push("</ul>"); | |
| $("#list").html(markupArray.join("")); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // evaluate expressions | |
| const createList = (items) => { | |
| switch ($.type(items)) { | |
| case "object": | |
| getItems(items); | |
| break; | |
| case "string": | |
| markupArray.push(`<li> <span> ${items} </span> </li>`); | |
| break; | |
| case "array": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // get items in the object | |
| const getItems = (items) => { | |
| for (const item in items) { | |
| // push li tags for parent | |
| // with nested opening ul tag for children | |
| markupArray.push(`<li> <a> ${item} </a> <ul>`); | |
| // evaluate expression for children | |
| createList(items[item]); | |
| // push closing tage | |
| markupArray.push("</ul></li>"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // create list function | |
| const createList = (items) => { | |
| switch ($.type(items)) { | |
| case "object": | |
| console.log(items); | |
| break; | |
| case "string": | |
| console.log(items); | |
| break; | |
| case "array": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const createList = (items) => { | |
| switch ($.type(items)) { | |
| case "object": | |
| console.log(items); | |
| break; | |
| case "string": | |
| console.log(items); | |
| break; | |
| case "array": | |
| console.log(items); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const CPOs = { | |
| 'StarCharge': { | |
| name: 'StarCharge', | |
| title: 'CPO', | |
| children: [ | |
| { | |
| name: 'SC_CS1', | |
| title: 'Charging Station', | |
| children: [ | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // test variables | |
| let contract | |
| const owner = accounts[0] | |
| const user = accounts[1] | |
| const notOwner = accounts[2] | |
| const unregistered = accounts[3] | |
| const name = 'John Doe' | |
| const age = 25 | |
| const value = 100 | |
| // global contract instance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it('should send the random value', async () => { | |
| // register user | |
| await contract.registerUser(user, name, age, { | |
| from: owner, | |
| }) | |
| // send the production value | |
| let result = await contract.send(value, { | |
| from: user, | |
| }) | |
| // test event |