Posted By

inamorix on 06/12/08


Tagged

js


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

hans


Array.prototype.query


 / Published in: JavaScript
 

  1. Array.prototype.query = function (q, mode) {
  2. var re = q.test;
  3. for (var r = [], i = 0, ix = this.length; i < ix; i++) {
  4. var m = 0;
  5. if (re && q.test(this[i])) m = 1;
  6. else
  7. switch (mode) {
  8. case +1: if (q < this[i]) m = 1; break;
  9. case -1: if (q > this[i]) m = 1; break;
  10. default: if (q === this[i]) m = 1;
  11. }
  12. if (m) r.push(mode == 0 ? i : this[i]);
  13. }
  14. return r;
  15. };

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: shawntse on June 12, 2008

FDSA

You need to login to post a comment.