Skip to content

Instantly share code, notes, and snippets.

@CarlosDanielDev
Last active March 4, 2019 01:36
Show Gist options
  • Save CarlosDanielDev/04c8e10f07dc5d560f3c90d02f5f1058 to your computer and use it in GitHub Desktop.
Save CarlosDanielDev/04c8e10f07dc5d560f3c90d02f5f1058 to your computer and use it in GitHub Desktop.
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