Skip to content

Instantly share code, notes, and snippets.

@santospatrick
Last active September 7, 2017 01:52
Show Gist options
  • Save santospatrick/355f208dacd2018a5196d27f0f37dfcf to your computer and use it in GitHub Desktop.
Save santospatrick/355f208dacd2018a5196d27f0f37dfcf to your computer and use it in GitHub Desktop.
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