Skip to content

Commit f47b79d

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

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

index.bs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,46 @@ 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+
2. 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. Let |row| be a new [=/map=]
134+
3. [=map/Set=] |row|["(index)"] to |index|
135+
4. [Set columns] with |value|, |row|, and |properties|
136+
5. [=list/Append=] |row| to |finalRows|
137+
2. Otherwise, if |tabularData| is a [=/map=], then:
138+
1. [=map/For each=] |key| → |value| of |tabularData|
139+
1. Let |row| be a new [=/map=]
140+
2. [=map/Set=] |row|["(index)"] to |key|
141+
3. [Set columns] with |value|, |row|, and |properties|
142+
4. [=list/Append=] |row| to |finalRows|
143+
3. If |finalRows| is [=list/empty=], perform <a abstract-op>Printer</a>("log", « |tabularData| »).
144+
4. Otherwise:
145+
1. Let |finalData| be a new [=/map=].
146+
2. [=map/Set=] |finalData|["rows"] to |finalRows|
147+
3. [=map/Set=] |finalData|["columns"] to |finalColumns|
148+
3. Perform <a abstract-op>Printer</a>("table", « |finalData| »).
149+
150+
To [set columns] given a |tabularDataItem|, a [=/map=] |row|, [=/list=] |finalColumns|, and an optional [=/list=] |properties|, perform the following steps.
151+
152+
1. If |tabularDataItem| is a [=/list=], then:
153+
1. Let |indices| be [=list/get the indices=] of |tabularDataItem|
154+
2. [=list/For each=] |index| of |indices|
155+
1. Let |value| be |tabularDataItem|[|index|]
156+
2. If |properties| is not [=list/empty=] and |properties| does not [=list/contain=] |index|, [=iteration/continue=]
157+
3. [=map/Set=] |row|[|index|] to |value|
158+
4. If |finalColumns| does not [=list/contain=] |index|, [=list/append=] |index| to |finalColumns|
159+
2. Othwerwise, if |tabularDataItem| is a [=/map=], then:
160+
1. [=map/For each=] |key| → |value| of |tabularDataItem|
161+
1. If |properties| is not [=list/empty=] and |properties| does not [=list/contain=] |key|, [=iteration/continue=]
162+
2. [=map/Set=] |row|[|key|] to |value|
163+
3. If |finalColumns| does not [=list/contain=] |key|, [=list/append=] |key| to |finalColumns|
164+
3. Otherwise, [=map/set=] |row|["Value"] to |tabularDataItem|
129165

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

0 commit comments

Comments
 (0)