Advertisement
xapu

Query translations

Feb 12th, 2019
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // In obj put the object that holds all the translations
  2. // Term is the string to search by
  3. let findTranslation = (obj, term) =>
  4.             Object.keys(obj)
  5.             .filter(word => obj[word].startsWith(term))
  6.             .map(key => ({[key]: obj[key]}))
  7.  
  8.  
  9. let findTranslationAnyMatch = (obj, term) =>
  10.             Object.keys(obj)
  11.             .filter(word => obj[word].toLowerCase().includes(term.toLowerCase()))
  12.             .map(key => ({[key]: obj[key]}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement