import { default } from "https://deno.land/x/simplestatistic@v7.7.1/src/unique_count_sorted.js";
For a sorted input, counting the number of unique values is possible in constant time and constant memory. This is a simple implementation of the algorithm.
Values are compared with ===
, so objects and non-primitive objects
are not handled in any special way.
Examples
uniqueCountSorted([1, 2, 3]); // => 3
uniqueCountSorted([1, 1, 1]); // => 1
uniqueCountSorted([1, 2, 3]); // => 3 uniqueCountSorted([1, 1, 1]); // => 1