Adam Collier

@adamcollier.bsky.social

adamcollier.co.uk

You should be using JavaScript sets more often Now in all browsers and Node - these 7 new set methods are key for when trying to compare two arrays or sets of data.

New JavaScript Set Methods
const set1 = new Set(['wes', 'kait']);
const set2 = new Set(['wes', 'scott']);
Difference
Elements in set2 but not in set1
set2.difference(set1)
> ['scott']
Intersection
Elements that exist in both sets
set1.intersection(set2)
> ['wes']
Symmetric Difference
Elements in either set, but not both
set1.symmetricDifference(set2)
> ['kait', 'scott']
Union
All elements from both sets
set1.union(set2)
> ['wes', 'kait', 'scott']
Is Disjoint From
True if sets share no elements
set1.isDisjointFrom(set2)
> false
Is Subset Of
True if all elements are in other set
set1.isSubsetOf(set2)
> false
Is Superset Of
True if it contains all other's elements
set1.isSupersetOf(set2)
> false

@astro.build Astro components are pretty powerful (just using standard JavaScript and html) veeeery surprised that you can’t use client directives on them though! Currently playing around with @motion.dev and it works great with a standard Astro file, I just want to load the js when visible 😅