search suggestion based on any letter of string

i am trying to write some java script code the auto suggest based on pretrial strings so to speak

here an example of what i mean:

if we have array of strings =>
[ ‘text’ , ‘apple’ , ‘texas’ , ‘time’ , ‘java’ , ‘java script’ , ‘pen’ ]

what i want to achieve is this :
when the user type ==> “te” the function should return this ==> ‘text’ and ‘texas’

BUT

if user type ==> “t*e” OR “t e” with space between the function should return this
==> ‘text’ , ‘texas’ , AND ‘time’ since it contains the tow letters no matter the oreder

the same if user type ==> “p*e” OR “p e” the result should be ==> ‘apple’ and ‘pen’
since booth contain the letters ‘p’ and ‘e’

here what i have done so far

const nameInput = document.getElementById('name')

const names = [ 'text' , 'apple' , 'texas' , 'time' , 'java' , 'java script' , 'pen' ]

nameInput.addEventListener('keyup', ()=> {
  // console.log(nameInput.value)
const text = nameInput.value.trim().replace(/s/g, '')
// console.log(text)
const a = names.filter(name => name.includes(text))
console.log(a)
})
<input type="text" placeholder="search"  id="name">