Hi everyone, I've been spending quite a bit of time trying to find a solution to this problem and I'm hoping someone can help me out.
The issue at hand is that I have 2 arrays - one containing multiple words from an address and another built with words entered in an input field. The current setup returns true only if the exact same word is entered in the input as it appears in the string array. However, I would like it to return true if there is a partial match as well. For example, if the string array contains "CENTER" and "RACHEL", entering "CEN EL" in the input should also return true because it partially matches 2 elements in the array.
Here's the code snippet I've put together:
function checker(arr, words) {
return words.every(v => arr.includes(v));
}
this.shippingAddress.forEach(address => {
const stringBuild = `${address.name} ${address.display_address} ${address.phone}`;
const arrayString = stringBuild.split(' ');
if (checker(arrayString, words)) {
_results.push(address);
}
});
An example of input for the array 'arrayString':
[
0: "CENTER"
1: "MANIKI"
2: "BRUCHESI"
3: "2225,"
4: ""
5: "STREET"
6: "RACHEL"
7: "EAST,"
8: "CITY"
9: "STUFF,"
10: "STUFF"
11: "STUFF"
12: "STUFF"
13: "STUFF"
]
For the array 'words':
[
0: "CEN"
1: "EL"
]
The expected output would be true because 'CEN' and 'EL' are included in the first array when passed through the checker function, even though they are not full words.