Skip to content

Commit 1f2faf9

Browse files
Add algorithm for console table
1 parent 7a9c402 commit 1f2faf9

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

index.bs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,47 @@ its \[[Prototype]] an empty object, created as if by
122122
<h4 id="table" oldids="table-tabulardata-properties,dom-console-table" method for="console">table(|tabularData|, |properties|)</h4>
123123

124124
Try to construct a table with the columns of the properties of |tabularData| (or use
125-
|properties|) and rows of |tabularData| and log it with a logLevel of "log". Fall
126-
back to just logging the argument if it can't be parsed as tabular.
127-
128-
<p class="XXX">TODO: This will need a good algorithm.</p>
125+
|properties|) and rows of |tabularData| and log it with a logLevel of "log".
126+
127+
1. Let |finalRows| be the new [=/list=], initially empty
128+
2. Let |finalColumns| be the new [=/list=], initially empty
129+
3. If |tabularData| is a [=/list=], then:
130+
1. Let |indices| be [=list/get the indices=] of |tabularData|
131+
2. [=list/For each=] |index| of |indices|
132+
1. Let |value| be |tabularData|[|index|]
133+
2. Perform [create table row] with |value|, |index|, |finalColumns|, |properties| that returns |row|
134+
3. [=list/Append=] |row| to |finalRows|
135+
4. Otherwise, if |tabularData| is a [=/map=], then:
136+
1. [=map/For each=] |key| → |value| of |tabularData|
137+
1. Perform [create table row] with |value|, |key|, |finalColumns|, and |properties| that returns |row|
138+
2. [=list/Append=] |row| to |finalRows|
139+
5. If |finalRows| is not [=list/empty=], then:
140+
1. Let |finalData| be a new [=/map=].
141+
2. [=map/Set=] |finalData|["rows"] to |finalRows|
142+
3. [=map/Set=] |finalData|["columns"] to |finalColumns|
143+
3. Perform <a abstract-op>Printer</a>("table", « |finalData| »).
144+
6. Otherwise, perform <a abstract-op>Printer</a>("log", « |tabularData| »).
145+
146+
To [create table row] given |tabularDataItem|, |rowIndex|, [=/list=] |finalColumns|, and optional [=/list=] |properties|, perform the following steps:
147+
148+
1. Let |row| be a new [=/map=]
149+
2. [=map/Set=] |row|["(index)"] to |rowIndex|
150+
3. If |tabularDataItem| is a [=/list=], then:
151+
1. Let |indices| be [=list/get the indices=] of |tabularDataItem|
152+
2. [=list/For each=] |index| of |indices|
153+
1. Let |value| be |tabularDataItem|[|index|]
154+
2. If |properties| is not [=list/empty=] and |properties| does not [=list/contain=] |index|, [=iteration/continue=]
155+
3. [=map/Set=] |row|[|index|] to |value|
156+
4. If |finalColumns| does not [=list/contain=] |index|, [=list/append=] |index| to |finalColumns|
157+
4. Otherwise, if |tabularDataItem| is a [=/map=], then:
158+
1. [=map/For each=] |key| → |value| of |tabularDataItem|
159+
1. If |properties| is not [=list/empty=] and |properties| does not [=list/contain=] |key|, [=iteration/continue=]
160+
2. [=map/Set=] |row|[|key|] to |value|
161+
3. If |finalColumns| does not [=list/contain=] |key|, [=list/append=] |key| to |finalColumns|
162+
5. Otherwise:
163+
1. [=map/set=] |row|["Value"] to |tabularDataItem|
164+
2. If |finalColumns| does not [=list/contain=] "Value", [=list/append=] "Value" to |finalColumns|
165+
6. Return |row|
129166

130167
<h4 id="trace" oldids="trace-data,dom-console-trace" method for="console">trace(...|data|)</h4>
131168

0 commit comments

Comments
 (0)