Posted By

Leech on 07/21/06


Tagged

arrays


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

sena
jkochis
nicolaspar


Diff v1.0


 / Published in: JavaScript
 

URL: http://jsfromhell.com/array/diff

Compares two arrays and returns the distinct values. Created: 2005.11.04

  1. /*
  2. **************************************
  3. * diff Function v1.0 *
  4. * Autor: Carlos R. L. Rodrigues *
  5. **************************************
  6. */
  7. diff = function(v, c, m){
  8. var d = [], e = -1, h, i, j, k;
  9. for(i = c.length, k = v.length; i--;){
  10. for(j = k; j && (h = c[i] !== v[--j]););
  11. h && (d[++e] = m ? i : c[i]);
  12. }
  13. return d;
  14. };

Report this snippet  

You need to login to post a comment.