1

I have two javascript arrays:

var lastWeek=["mofakkarul2013innovation", "basu2013monitoring", "petrov2013applying", "truong2013impact", "truong2013reduction", "laefer2013planning", "aksoy2013relative", "dormer2013carbon", "o2008plenary", "pakrashi164review", "zhao2013identification", "carey2013investigating", "jacob2013icwim", "ferreira2013life", "ferreira2013life", "cottercan", "doyleoptimal", "conlon2013anatomy", "cottercan", "doyleoptimal", "conlon2013anatomy", "golsdorfgreen", "golsdorfgreen", "hochstrasserneeded", "dieterich2013greenhouse", "hassanzadeh2013identification", "nedovic2013planning", "parnellbayesian", "fennell2013simulating", "saunders2013land", "nichonchubhair2013greenhouse", "saunders2013impact", "gioria2013biological", "gauthier2013genetic", "colman2013ventbase", "yearsley2013effect", "boots2013linking", "balter2013contrasting", "roarty2013permanent", "teresa2013beef", "andriuzzi2013drilosphere", "hochstrasserneeded", "dieterich2013greenhouse", "hochstrasserneeded", "dieterich2013greenhouse", "hochstrasserneeded", "dieterich2013greenhouse", "georgiopoulou2013basement", "benetti2013late", "georgiopoulou2013critical", "parnellbayesian", "fennell2013simulating", "saunders2013land", "nichonchubhair2013greenhouse", "saunders2013impact", "gioria2013biological", "balme2013geomorphology", "courtney2013statistical", "courtney2013statistical", "tuffy2013rotate", "page2013three", "tuffy2013rotate", "page2013three", "mcdermottfrontiers", "deininger2013investigating", "comas2013impacts", "convery2013european", "nasr2013derivation", "feeley2013regional", "ahilan2013bankfull", "neil2013modelling", "o2013parameter", "mcnamara2013experimental", "courtney2013statistical", "courtney2013high", "georgiopoulou2013basement", "benetti2013late", "georgiopoulou2013critical", "vogfjord2013extending", "jonsdottir2013coda", "ying2013time", "ferreira2013life", "rafieetwo", "banner2013unexpected", "rafiee2013numerical", "viotti2013emergence", "stefanakis2013can", "carbone2013extreme", "nasr2013derivation", "feeley2013regional", "ahilan2013bankfull", "neil2013modelling", "o2013parameter", "murphy2013ethics", "mcnamara2013experimental", "georgiopoulou2013basement", "georgiopoulou2013basement", "cooper2013mode", "carolan2013effect", "tukovic2013finite", "carolan2013arbitrary", "kanyanta2013bio", "mohan2013effect", "walter2013detachment", "doyle2013developing", "fennell2013simulating", "saunders2013land", "nichonchubhair2013greenhouse", "saunders2013impact", "gioria2013biological", "vogfjord2013extending", "jonsdottir2013coda", "ying2013time", "courtney2013statistical", "schopfer2013three", "schopfer2013failure", "aksoy2013relative", "mcdermottfrontiers", "deininger2013investigating", "comas2013impacts", "rafieetwo", "banner2013unexpected", "rafiee2013numerical", "viotti2013emergence", "stefanakis2013can", "carbone2013extreme", "qi2013investigations", "li2013investigation", "liu2013review", "liu2013digital", "li2013k", "guo2013analysis", "sabol2013extracting", "sabol2013extracting", "zhao2013unitary", "callan2013crisis", "holohan2013stress", "nasr2013derivation", "feeley2013regional", "ahilan2013bankfull", "neil2013modelling", "o2013parameter", "georgiopoulou2013basement", "georgiopoulou2013basement", "schopfer2013three", "schopfer2013failure", "mofakkarul2013innovation", "fennell2013simulating", "saunders2013land", "nichonchubhair2013greenhouse", "saunders2013impact", "gioria2013biological", "mcainsh2013measurement", "mcainsh2013measurement", "ali2013identification", "ali2013brassinosteroid", "ali2013insights", "diamond2013fusarium", "reape2013commentary", "diamond2013fusarium", "hochstrasserneeded", "dieterich2013greenhouse", "schopfer2013three", "schopfer2013failure", "schopfer2013three", "schopfer2013failure", "callan2013crisis", "holohan2013stress", "callan2013crisis", "holohan2013stress", "nasr2013derivation", "feeley2013regional", "ahilan2013bankfull", "neil2013modelling", "o2013parameter", "nasr2013derivation", "feeley2013regional", "ahilan2013bankfull", "neil2013modelling", "o2013parameter", "schopfer2013three", "schopfer2013failure", "maischberger2013expression", "liu2013hplc", "miranda2013real", "zhao2013preliminary", "zhao2013preliminary", "zhao2013preliminary", "zhao2013preliminary", "boots2013linking"]

var thisWeek=["basu2013monitoring", "gonzalez2013impact", "petrov2013applying", "truong2013impact", "truong2013reduction", "laefer2013planning", "truong2013combining", "aksoy2013relative", "dormer2013carbon", "o2008plenary", "pakrashi164review", "zhao2013identification", "carey2013investigating", "jacob2013icwim", "ferreira2013life", "convery2013european", "convery2013reflections", "kroonsixth", "wan2013bootstrapping", "o2013smart", "hynes2013towards", "o2013pervasive", "sandygulova2013study", "carr2013sixth", "dragone2013programming", "cottercan", "doyleoptimal", "conlon2013anatomy", "avino2013sovereign", "scott2013design", "igoe2013investigation", "gavin2013effect", "gavin2013base", "doherty2013pile", "golsdorfgreen", "murphy2013mortgage", "scott2013design", "hochstrasserneeded", "dieterich2013greenhouse", "hassanzadeh2013identification", "nedovic2013planning", "hassanzadeh2013identification", "nedovic2013planning", "fennell2013simulating", "prescher2013short", "saunders2013land", "nichonchubhair2013greenhouse", "saunders2013impact", "gioria2013biological", "scottisolation", "dool2013phylogeography", "kirwan2013phylomedicine", "teeling2013making", "springer2013technical", "hughes2013using", "lundy2013prey", "gauthier2013genetic", "colman2013ventbase", "yearsley2013effect", "boots2013linking", "balter2013contrasting", "roarty2013permanent", "teresa2013beef", "andriuzzi2013drilosphere", "von2013skull", "hochstrasserneeded", "dieterich2013greenhouse", "kochmannenvironmental", "salvaterraimpacts", "green2013physical", "green2013effects", "crowe2013large", "gollety2013contribution", "bolger2013hierarchical", "andriuzzi2013drilosphere", "connolly2013improved", "georgiopoulou2013basement", "benetti2013late", "georgiopoulou2013critical", "parnellbayesian", "fennell2013simulating", "prescher2013short", "saunders2013land", "nichonchubhair2013greenhouse", "saunders2013impact", "gioria2013biological", "balme2013geomorphology", "ramsdale2013sinuous", "courtney2013statistical", "courtney2013high", "scott2013design", "tuffy2013rotate", "page2013three", "brooks2013production", "mcdermottfrontiers", "deininger2013investigating", "comas2013impacts", "comas2013impacts", "warren2013archaeological", "convery2013european", "nasr2013derivation", "feeley2013regional", "ahilan2013bankfull", "neil2013modelling", "o2013parameter", "mcnamara2013experimental", "courtney2013statistical", "courtney2013high", "georgiopoulou2013basement", "benetti2013late", "georgiopoulou2013critical", "vogfjord2013extending", "jonsdottir2013coda", "ying2013time", "ferreira2013life", "ferreira2013life", "nasr2013derivation", "feeley2013regional", "ahilan2013bankfull", "neil2013modelling", "o2013parameter", "murphy2013ethics", "mcnamara2013experimental", "georgiopoulou2013basement", "georgiopoulou2013basement", "cooper2013mode", "carolan2013effect", "tukovic2013finite", "carolan2013arbitrary", "kanyanta2013bio", "mohan2013effect", "walter2013detachment", "doyle2013developing", "fennell2013simulating", "prescher2013short", "saunders2013land", "nichonchubhair2013greenhouse", "saunders2013impact", "gioria2013biological", "vogfjord2013extending", "jonsdottir2013coda", "ying2013time", "doyle2013developing", "courtney2013statistical", "courtney2013high", "schopfer2013three", "schopfer2013failure", "schopfer2013three", "schopfer2013failure", "mcdermottfrontiers", "deininger2013investigating", "comas2013impacts", "comas2013impacts", "rafieetwo", "banner2013unexpected", "rafiee2013numerical", "viotti2013emergence", "stefanakis2013can", "carbone2013extreme", "dutykh2013use", "qi2013investigations", "li2013investigation", "liu2013review", "liu2013digital", "li2013k", "guo2013analysis", "sabol2013extracting", "sabol2013extracting", "zhao2013unitary", "ryle2013calibration", "callan2013crisis", "holohan2013stress", "igoe2013investigation", "gavin2013effect", "gavin2013base", "doherty2013pile", "lynch2013utilisation", "everard2013evaluation", "o2013feasibility", "devlin2013fuel", "wolff2013practical", "sweeney2013development", "mcdonnell2013photo", "omara2013anaerobic", "mcdonnell2013fabrication", "goodbody2013regional", "narancic2013highly", "molloy2013engineering", "babu2013current", "casey2013effect", "brooks2013production", "o2013anti", "nasr2013derivation", "feeley2013regional", "ahilan2013bankfull", "neil2013modelling", "o2013parameter", "georgiopoulou2013basement", "georgiopoulou2013basement", "schopfer2013three", "schopfer2013failure", "mofakkarul2013innovation", "fennell2013simulating", "prescher2013short", "saunders2013land", "nichonchubhair2013greenhouse", "saunders2013impact", "gioria2013biological", "mcainsh2013measurement", "brooks2013production", "ali2013identification", "ali2013brassinosteroid", "ali2013insights", "diamond2013fusarium", "mullins2013method", "reape2013commentary", "diamond2013fusarium", "hochstrasserneeded", "dieterich2013greenhouse", "schopfer2013three", "schopfer2013failure", "kavanagh2013microbial", "amadio2013filamentous", "hamza2013isolation", "robertson2013synthesis", "callan2013crisis", "holohan2013stress", "feeley2013regional", "o2013performance", "nasr2013derivation", "feeley2013regional", "ahilan2013bankfull", "neil2013modelling", "o2013parameter", "kochmannenvironmental", "salvaterraimpacts", "green2013physical", "green2013effects", "crowe2013large", "gollety2013contribution", "schopfer2013three", "schopfer2013failure", "maischberger2013expression", "liu2013hplc", "miranda2013real", "zhao2013preliminary", "kavanagh2013microbial", "amadio2013filamentous", "hamza2013isolation", "robertson2013synthesis", "brooks2013production", "narancic2013highly", "molloy2013engineering", "babu2013current", "casey2013effect", "brooks2013production", "o2013anti", "boots2013linking"]

'lastWeek' is last week's list of papers. 'thisWeek' is this week's list of papers.

How do I get just the new papers in jQuery? (i.e. exclude all the papers that appeared last week)

I tried:

var diff=$(thisWeek).not(lastWeek).get()

but this gives me the wrong diff -- none of the papers in the diff are in this week's list: they're all in last week's diff. ;(

Many thanks in advance,

Eamorr
  • 9,872
  • 34
  • 125
  • 209

4 Answers4

1

From the Source

jQuery.grep(array1, function(el)
{
    return jQuery.inArray(el, array2) == -1;
});
Community
  • 1
  • 1
Pandiyan Cool
  • 6,381
  • 8
  • 51
  • 87
1
var diff = [];
var i = 0;
jQuery.grep(lastWeek, function(el) {
    if (jQuery.inArray(el, thisWeek) == -1) diff.push(el);
    i++;
});
Janith Chinthana
  • 3,792
  • 2
  • 27
  • 54
1

It's supposed to be

var diff=$(lastWeek).not(thisWeek).get();

You are doing it right, but why are you using different variables in the jQuery?

EDIT: If above is not working (which I think is correct btw) then create a new array,

var _diff = new Array();

and do it like:

_diff = jQuery.grep(lastWeek, function (whatsNew) {
     return jQuery.inArray(whatsNew, thisWeek) < 0;
});
George Violaris
  • 315
  • 1
  • 10
1
var difference = [];
for(paper in thisWeek){    
    if($.inArray(thisWeek[paper], lastWeek) == -1){
    difference.push(thisWeek[paper]);    
    }
}
achakravarty
  • 418
  • 3
  • 7