let suggestions = [
"Degree Foundation",
"Business HND With Marketing Management",
"Business HND With Human Resource Management",
"Business HND With Business Analytics",
"Australian Degree Year 1 Diploma",
"BA (Hons) International Business and Finance",
"BA Global Business (Top-Up)",
"BSc (Hons) Business Management with International Business",
"BSc (Hons) Business Management with Marketing Management",
"BSc (Hons) Business Management with Human Resource Management",
"MBA International Business",
"MBA (General)",
"MBA in Human Resources Management",
"MBA with Business Analytics",
"MSC Strategic Marketing",
"CIMA",
];
inputs: any English character or characters for example – "hn", "mang"
expect output: which contains input character array values in the above array for example –
for – "hn"
"Business HND With Marketing Management",
"Business HND With Human Resource Management",
"Business HND With Business Analytics",
for – "manag"
"Business HND With Marketing Management",
"Business HND With Human Resource Management",
"BSc (Hons) Business Management with Marketing Management",
"BSc (Hons) Business Management with Human Resource Management",
"MBA in Human Resources Management",
3
Answers
use a fuzzy search library like: https://github.com/leeoniya/uFuzzy
You can use the filter() method along with the includes() method to find every element in the suggestions array that includes a specified string.
Edit: I am not sure how scalable this approach is, but for "smaller" suggestion lists it should definitly work as expected without having to use external libaries etc.
You don’t even need javascript!