Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. function spellLookup(event)
  2. {
  3. if (!searchingForSpell) //do not do two searches at the same time
  4. {
  5. var spellStartWithMatches = [];
  6. var spellMatches = [];
  7.  
  8. searchingForSpell = true;
  9. for (var i = 0, l = spells.length; i < l; i++)
  10. {
  11. if (spells[i].name.toLowerCase().startsWith(event.target.value.toLowerCase()))
  12. {
  13. spellStartWithMatches.push({"name" : spells[i].name, "index" : i});
  14. }
  15. else if (spells[i].name.toLowerCase().includes(event.target.value.toLowerCase()))
  16. {
  17. spellMatches.push({"name" : spells[i].name, "index" : i});
  18. }
  19. }
  20. searchingForSpell = false;
  21.  
  22. console.log(JSON.stringify(spellStartWithMatches));
  23. console.log(JSON.stringify(spellMatches));
  24. //display spell matches in a list below the + add new spell +
  25. //on spell click select spell by the index, and add it to the slot
  26. //don't be a dick, do not iterate everything everytime
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement