Joins, Drill 2

Write the function createTable to complete the following snippet and create the elements in a table, based on the data array.

  <table id="table">
    data = [{ c1: "row 1, col 1", c2: "row 1, col 2" }, 
            { c1: "row 2, col 1", c2: "row 2, col 2" }];
    selection ="#table");
    createTable(selection, data); // write this function

The elements in the resulting table should look like this:

<table id="table">
    <td>row 1, col 1</td>
    <td>row 1, col 2</td>
    <td>row 2, col 1</td>
    <td>row 2, col 2</td>

Hint. Remember the general pattern in d3’s API:

So far, you have called d3 like this: d3.selectAll(...).data(constant_array).

Try it

HTML Output