in Education by
I want to optimize this code instead of using td(String.valueof(dataset.get())) mutliple times. I am relatively new to lambda expressions usage and not able to figure out a better way than this Code need to be optimized return table(thead(tr(each(columnHeaders, header -> th(String.valueOf(header))))), tbody(each(myList, dataset -> tr(td(String.valueOf(dataset.get(0))), td(String.valueOf(dataset.get(1))), td(String.valueOf(dataset.get(2))), td(String.valueOf(dataset.get(3))), td(String.valueOf(dataset.get(4))), td(String.valueOf(dataset.get(5))), td(String.valueOf(dataset.get(6))), td(String.valueOf(dataset.get(7))), td(String.valueOf(dataset.get(8))), td(String.valueOf(dataset.get(9))), td(String.valueOf(dataset.get(10))) )) ) ) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I see, you're using j2html. I think you can do this in one line like this: return table(thead(tr(each(columnHeaders, header -> th(String.valueOf( tbody(each(myList, dataset -> each(dataset, data -> td(data))))) But it probably reads better if you break it out a little bit: return table(thead(tr(each(columnHeaders, header -> th(String.valueOf(header))))), tbody(each(myList, dataset -> each(dataset, data -> td(String.valueOf(data)))))); All that I've done here, is inside your call to tbody you say each(myList..., then just do each again for every element of myList. If you made sure that columnHeaders and myList were typed collections (like List) then you could do something like this: return table(thead(tr(each(columnHeaders, TagCreator::header))), tbody(each(myList, dataset -> each(dataset, TagCreator::td))));

Related questions

0 votes
    given I have a list of items that all inherit from the same base class: class Item { protected ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    given I have a list of items that all inherit from the same base class: class Item { protected ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    given I have a list of items that all inherit from the same base class: class Item { protected ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    given I have a list of items that all inherit from the same base class: class Item { protected ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Below is a crude for-loop to illustrate what I need to do. Basically, if there are any 'Variable' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Below is a crude for-loop to illustrate what I need to do. Basically, if there are any 'Variable' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    R comes with a ________ to help you optimize your code and improve its performance. (a) debugger (b) ... Analysis of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Which component is responsible to optimize bytecode to machine code? (a) JVM (b) JDK (c) JIT (d) ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    It is a proven fact that reducing the CCN of code is known to reduce the number of errors or bugs in the code. (i)False (ii)True...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    It is a proven fact that reducing the CCN of code is known to reduce the number of errors or bugs in the code. (i)False (ii)True...
asked Oct 5, 2020 in Technology by Editorial Staff
0 votes
    While the code is growing big it is getting harder and harder to keep everything well organized. One thing ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    ________ automates an action or attack so that repetitive tasks are done at a faster rate. (a) Auto-bots (b) ... Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 4, 2021 in Education by JackTerrance
0 votes
    Which forms simplifies and ensures that there are minimal data aggregates and repetitive groups: (a) 1NF (b ... from Normal Forms in portion Normalization of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    NOTE: I am not set on using VI, it is just the first thing that came to mind that might be able to do what I need ... there an automated way I can take the text: and change it to:...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    NOTE: I am not set on using VI, it is just the first thing that came to mind that might be able to do what I need ... there an automated way I can take the text: and change it to:...
asked Mar 19, 2022 in Education by JackTerrance
...