+sub featurescore {
+ # relative amount of support for given feature
+ state $statspts = { y=>10, 'y x'=>9, a=>5, j=>2, p=>1 };
+ my $rank = 0;
+ if (my $row = shift) {
+ while (my ($browser, $vercols) = each %versions) {
+ my $div = 0; # multiplier exponent (decreased to lower value)
+ my @vers = map { $row->{$browser}->{$_} } @$vercols;
+ if (my $current = $caniuse->{agents}->{$browser}->{versions}->[-3]) {
+ my @future; # find upcoming releases (after current)
+ for (reverse @$vercols) {
+ last if $_ eq $current;
+ push @future, pop @vers;
+ $_ eq 'u' and $_ = $vers[-1] for $future[-1]; # inherit latest value if unknown
+ }
+ splice @vers, -1, 0, @future; # move ahead to decrease precedence
+ }
+ $rank += $statspts->{$_} * 2**($div--) for reverse @vers;
+ }
+ }
+ return $rank;
+}
+
+for my $id (sort {
+ featurescore($caniuse->{data}->{$b}->{stats})
+ <=> featurescore($caniuse->{data}->{$a}->{stats})
+} keys %{ $caniuse->{data} }) {