Q:

How to make searching in JS

I have a string like below.
const a = "The school is big."

And I want to make searching function.
function searching(q){
    ...
}

// searching(the) -> true
// searching(e s) -> true
// searching(oolis) -> true
// searching(the big) -> false        

Could you recommend some solution for this case? 

A:

If you remove the spaces from both your input string and search string using .replace(), and convert both to lower case using toLowerCase(), then you can use the .includes() method to check if your search string falls within your input string: 

const a = "The school is big.";

function searching(str, q) {
  const str_no_space = str.replace(/\s+/g, '').toLowerCase();
  const q_no_space = q.replace(/\s+/g, '').toLowerCase();
  return str_no_space.includes(q_no_space);
}

console.log(searching(a, "the")); // -> true
console.log(searching(a, "e s")); // -> true
console.log(searching(a, "oolis")); // -> true
console.log(searching(a, "the big")); // -> false

