facetwp check if any facets are selected

<?php
/**
  * adds js code to check for any facets being selected
  */
add_action( 'wp_head', function() { ?>
    <script>
        (function($) {
            $(document).on('facetwp-loaded', function() {
                var facets_in_use = function() {
                    var in_use = false;

                    $.each(FWP.facets, function(name, val) {
                        if (0 < val.length && 'paged' !== name) {
                            in_use = true;
                            return false; // exit loop
                        }
                    });

                    return in_use;
                }
                if ( facets_in_use() ) {
                    // do stuff when there are facets with selections
                } else {
                    // do stuff like hide reset button when there are no facets selected
                }
            });
        })(jQuery);
    </script>
<?php }, 10, 2 );