Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. userUtils.search = {};
  2. userUtils.search.byName = function(name, fuzzy) {
  3. fuzzy = fuzzy || false;
  4. //let u = fuzzy;
  5. let expre = new RegExp(`^${name}`, 'i');
  6. let matchusers = users.filter(function search(item) {
  7. if (fuzzy === false) {
  8. if (item.name.first === name || item.name.last === name) {
  9. return item;
  10. }
  11. } else {
  12. if (expre.test(item.name.first) || expre.test(item.name.last)) return item;
  13. }
  14. });
  15. return matchusers;
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement