Example 1 — Collection With Duplicates
Build a collection that is out of order and lists some nodes twice, then clean it up.
var a = document.getElementById("a");
var b = document.getElementById("b");
var c = document.getElementById("c");
var $set = $([c, a, c, b, a]);
console.log($set.length); // 5
$set.uniqueSort();
console.log($set.length); // 3 → a, b, c How It Works
- Build.
$([c, a, c, b, a])keeps the array order and repeats. - Dedupe. Repeated references to the same node are removed.
- Sort. The three nodes end up in document order: a, b, c.

