Last active
March 4, 2019 01:36
-
-
Save CarlosDanielDev/04c8e10f07dc5d560f3c90d02f5f1058 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const normalize = str => { | |
| return String(str) | |
| .normalize('NFD') | |
| .replace(/[\u0300-\u036f]/g, "") | |
| } | |
| // Main function | |
| const findBySimilarity = (list = [], strings = '', keys = [], terms = normalize( strings ).toLowerCase().split(' ')) => { | |
| return list | |
| .filter(el => terms | |
| .some(t => keys | |
| .some(k => normalize( el[ k ] ).toLowerCase().includes( t ) ) ) ) | |
| } | |
| export default findBySimilarity | |
| //uso | |
| array = [{"chave1":"valor1"},{"chave2":"valor2"}] | |
| const result = findBySimilarity(array, 'valor1' ['chave1', 'chave2']) | |
| // creditos https://github.com/Woodsphreaker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment