JSFiddle - React, Tailwind, and code Playground

by Farzad YZ

JavaScript

function findFacilities(input) {
  var splatByNewLine = input.split('\n');
  var N = splatByNewLine[0];
  var boundary = +N + 1;
  var facilities = splatByNewLine.slice(1, boundary);
  var text = splatByNewLine.slice(boundary);

  var found = facilities.forEach(fac => {
    var regex = new RegExp(fac, 'ig');
    var txt = text.join('');
    return txt.match(regex);
  });
  
  return found.sort((a,b) => a>b);
}

findFacilities(`5
wifi
swimming pool
garden
beach
tennis court
Our hotel is a very luxurious one, we are committed to provide the best holiday, you can always relax on our private beach, we provide four amazing tennis courts. WIFI is available in all areas.`)