I have an array like this
const arr = ["Apple", "Banana", "Cherry", "Orange", "Avocado", "Ananas", "Pineapple];
I need a function that returns an array with all the Elements from arr, that match the given character sequence. The order of the characters is of importance.
Given "ppl" the function should return ["Apple", "Pineapple"].
Given "n" the function should return ["Banana", "Orange", "Ananas", "Pineapple"].
Given "voca" the function shoould return ["Avocado"]
Given "rr" the function should return ["Cherry"], while given a "r" the function should return ["Cherry", "Orange"].
>Solution :
try this
const arr = ["Apple", "Banana", "Cherry", "Orange", "Avocado", "Ananas", "Pineapple"];
const search = query => arr.filter(s => s.toLowerCase().includes(query))
console.log(search("n"))
console.log(search("ppl"))