Skip to content

Commit 0e7662b

Browse files
committed
table.dedup etc
1 parent b8dff01 commit 0e7662b

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

docs/Runtime Environment/Table.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,38 @@ print(dumpvar(t:values())) -- { "foo", "bar", "value1", "value2" }
272272
### `table.countvalues`
273273
Returns a key-value based table which describes how many times a value appears inside of a table.
274274
#### Parameters
275-
1. The table
275+
1. The table.
276276
```pluto
277277
local t = {
278278
1,
279-
2, 2
279+
2, 2,
280280
3, 3, 3,
281-
4, 4, 4, 4
282-
["key1"] = "value"
283-
["key2"] = "value"
281+
4, 4, 4, 4,
282+
["key1"] = "value",
283+
["key2"] = "value",
284284
}
285285
286286
print(dumpvar(t:countvalues())) -- { [1] = 1, [2] = 2, [3] = 3, [4] = 4, ["value"] = 2 }
287287
```
288+
---
289+
### `table.dedup`, `table.deduplicate`
290+
Sets any keys with a duplicate value in the table to nil.
291+
#### Parameters
292+
1. The table.
293+
```pluto
294+
local t = {
295+
1,
296+
2, 2,
297+
3, 3, 3,
298+
4, 4, 4, 4,
299+
}
300+
301+
print(dumpvar(t:dedup())) -- { [1] = 1, [2] = 2, [4] = 3, [7] = 4 }
302+
print(dumpvar(t:dedup():reorder())) -- { 1, 2, 3, 4 }
303+
```
304+
### `table.deduped`, `table.deduplicated`
305+
Copying variant of `table.dedup`/`table.deduplicate`; returns a new table instead of modifying the input table. Note that nested tables will not be copied.
306+
288307
---
289308
### `table.chunk`
290309
Generates a new table which collects the values of the input and represents them in chunks of a specified size.

0 commit comments

Comments
 (0)