diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-01-07 11:00:49 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-01-07 11:37:49 +0100 |
commit | eafa321279778d737861c57437fe4fc14c26d36e (patch) | |
tree | 288ee5dd0c56cbf00025825691154568a6c23dce /main.c | |
parent | 1377e23afff90128b18ac60c10071295fc0afbab (diff) |
lib: implement uniq() function
The uniq() function allows extracting all unique values from a given input
array in an efficient manner. It is roughly equivalent to the following
ucode idiom:
let seen = {}
let unique = filter(array, item => !seen[item]++);
In contrast to the code above, `uniq()` does not rely on implicit
stringification of item values but performs strict equality tests internally.
If equivalence of stringified results is desired, the following code can
be used:
let unique = uniq(map(array, item => "" + item));
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'main.c')
0 files changed, 0 insertions, 0 deletions