-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilterList.js
More file actions
38 lines (31 loc) · 979 Bytes
/
filterList.js
File metadata and controls
38 lines (31 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* filterList
Used in a search bar. Recive a word and search for it in a list and than return a filtered list.
#params
searchWord -> The keyword used to find an item
list -> The list you wanna filter
#return
filteredList -> new list filtered by a keyword
*/
export function filterList(searchWord, list) {
let filteredList = list;
if ( searchWord.length > 0 ) {
searchWord = removeAcentuations(searchWord);
filteredList = list.filter(function(item){
const formatedName = removeAcentuations(item.nome);
if ( formatedName.search(searchWord) > -1 ){
return item;
}
});
}
return(filteredList);
};
function removeAcentuations(word) {
word = word.toLowerCase();
word = word.replace(/[àáâãäå]/,"a");
word = word.replace(/[èéêë]/,"e");
word = word.replace(/[ìí]/,"i");
word = word.replace(/[õö]/,"o");
word = word.replace(/[úùü]/,"u");
word = word.replace(/[ç]/,"c");
return word;
}