Is it possible to return indexes from an array based on a search term, regardless of the order of characters in the array?
const array = ['hell on here', '12345', '77788', 'how are you llo'];
function findMatchingIndexes(arr, searchTerm) {
const indexArray = [];
for(let i = 0; i < arr.length; i++) {
if (searchTerm.charAt(i) <= arr.indexOf(i)) {
indexArray.push(i);
}
}
return indexArray;
}
document.write(findMatchingIndexes(array, "hello"));
This code should output 0 and 3 as the matching indexes in the array. How would you approach this problem?