Last active
September 7, 2017 01:52
-
-
Save santospatrick/355f208dacd2018a5196d27f0f37dfcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import removeAccents from 'remove-accents'; | |
/** | |
* Filter list based on certain attribute by some text | |
* @param {array} list | |
* @param {string} searchText | |
* @param {string} attribute | |
* @returns {array} new filtered list | |
*/ | |
export function filterList(list, searchText, attribute) { | |
return list.filter(item => { | |
let itemAttribute = removeAccents( | |
item[attribute].toLowerCase().split(' ').join(''), | |
); | |
return itemAttribute.includes( | |
removeAccents(searchText.toLowerCase().split(' ').join('')), | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment