Merge functionality from 2 jQuery snippets

Solution:

$(function(){

  $(document).on('click', "[class*='fs-']", function(e) {
    // getting all classes and converting them to an array
    Array.from($(this).prop('classList'))
      // filtering non 'fs-' classes 
      .filter(x => x.match(/^fs-/))
      // stripping leading `fs-`
      .map( x => { 
        const [a,b] = x.match(/^fs-(\w+)/i); 
        return b; 
      // clicking all elements having data atribute matching the fs- classes from the collection  
      }).forEach( x => {
        console.log(x); 
        $("[data-value='${x}']").click(); 
      });
  });

  var FWP = {
    facets: {chapter:[]}, 
    is_reset: false,
    refresh: function() {}
  };
  
  $(".chapter").click(function () {
    /* clear all */
    $.each(FWP.facets, function(name, val) {FWP.facets[name] = [];});
    var [chapter] = Array.from($(this).prop('classList'))
      // filtering non 'show-' classes 
      .filter(x => x.match(/^show-/))
      // stripping leading `show-`
      .map( x => { 
        const [a,b] = x.match(/^show-(\w+)/i); 
        return b; 
      });
    /* make selection */
    FWP.facets['chapter'] = [chapter]; 
    FWP.is_reset = true; // don't parse facets
    FWP.refresh();
    console.log(FWP);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<div id="element" class="fs-one fs-two fs-three other1 other2">Click here</div>

<hr/>
Second part (click some of the entries)
<hr/>

<div class="chapter show-book">Book</div>
<div class="chapter show-window">Window</div>
<div class="chapter show-chair">Chair</div>